How to get a character from a string

Hi so i am making a simple scoreboard with dreamlo and when i get the data with inernet get function i get a lof of things like this: “player:carmine|46|14:00 etc.” so how do i get a lets say the number 46 from that? i tried the manupilation of text but it doesnt work. sry bad english

You’re going to have to do a lot more testing using substrings and other text manipulation expressions. Unfortunately, tearing apart strings (text) is a complicated process.

For your example above, it would be this:

SubStr(  //(to pull out a piece of your text line, requires text, the first character number to start from, and the length of characters to return)
"player:carmine|46|14:00", //(your string. Could also be stored as a variable)
(StrFind( //(to find the first character needed, basically "return the number of characters I have to go past to find the character I want". We will call this A.)

"player:carmine|46|14:00", //(your string. Could also be stored as a variable)

"|" //(the first character you're trying to find the character number of)

) //(to close the StrFind)

+1), //(too add 1 to the StrFind's result, since you don't want to include the |, this makes it so you start at the next character)

StrFindLastFrom( //(to find the character count/number of the last instance of a character needed in your string, we will call this B)

"player:carmine|46|14:00", //(Your string)

"|", //(the character you're trying to find the last instance of)

StrLength("player:carmine|46|14:00") //(finding the total length of your string

) //(closing the StrFindLastFrom)
-(StrFind("player:carmine|46|14:00", "|")+1)  //(You are now finding the first character again so you can subtract it from the total number of characters to the lastfrom, so you are saying "return only this number of characters between A and B")
) //(closing everything)

In full, you’d have this:
SubStr("player:carmine|46|14:00",(StrFind("player:carmine|46|14:00", "|")+1),StrFindLastFrom("player:carmine|46|14:00", "|", StrLength("player:carmine|46|14:00"))-(StrFind("player:carmine|46|14:00", "|")+1))

Using this in a string variable results like this:


Will result in the following variable when previewed:

Unfortunately, you’re going to have to do different math for each different section you want to cut apart. It’s totally doable, though.

1 Like

Thank you so much!!! my brain would never.

Understandable. String manipulation is a pain. I recommend, if you can, calling the data separately and store them as variables, then just merging them together afterwards for the desired info. SO MUCH EASIER than trying to split apart strings.

<?xml version="1.0" encoding="utf-8"?><root><location><name>Busovaca</name><region>Federation of Bosnia and Herzegovina</region><country>Bosnia and Herzegovina</country><lat>44.1</lat><lon>17.88</lon><tz_id>Europe/Sarajevo</tz_id><localtime_epoch>1612545434</localtime_epoch><localtime>2021-02-05 18:17</localtime></location><current><last_updated_epoch>1612544415</last_updated_epoch><last_updated>2021-02-05 18:00</last_updated><temp_c>11</temp_c><temp_f>51.8</temp_f><is_day>0</is_day><condition><text>Clear</text><icon>//cdn.weatherapi.com/weather/64x64/night/113.png</icon><code>1000</code></condition><wind_mph>0</wind_mph><wind_kph>0</wind_kph><wind_degree>205</wind_degree><wind_dir>SSW</wind_dir><pressure_mb>1016</pressure_mb><pressure_in>30.5</pressure_in><precip_mm>0</precip_mm><precip_in>0</precip_in><humidity>82</humidity><cloud>0</cloud><feelslike_c>10.8</feelslike_c><feelslike_f>51.4</feelslike_f><vis_km>10</vis_km><vis_miles>6</vis_miles><uv>4</uv><gust_mph>4.5</gust_mph><gust_kph>7.2</gust_kph></current></root>

could you the same but for this one pull the numbers after temp_c

Sadly, I despise dealing with strings. I did the above to show you how it could be done. My brain can’t really manage going through and doing more of them.

You can find all of the string expressions and definitions here: Expressions reference [GDevelop wiki]

1 Like

I know it’s not within everyone’s experience for this development tool, but if you do know javascript it’s fairly trivial to do more advanced string manipulation in a javascript block or extension function like this using regular expressions: