How do I remove last element of a string, comma separated?

Get help using Construct 2

Post » Tue Sep 16, 2014 3:07 pm

Hi,

how can I remove the last part of a string? All the elements are separated by a "," and there's is always another "," at the end.

String will usually look something like this:

"Ingrediente8,Ingrediente13,Molho18,Ingrediente2, Ingrediente9"

I need a way to delete the last element of that string.
Please tag me with @caiorosisca if your post is refering to me :). I don't always follow the topics I answer.
B
11
S
4
G
1
Posts: 272
Reputation: 1,643

Post » Tue Sep 16, 2014 3:30 pm

You overwrite the old string to a new string using a loop
for loop =tokencount(yourtext, ",")-1, newstring set string to newstring & tokenat(yourtext, loopindex, ",")&","
Image ImageImage
B
171
S
50
G
179
Posts: 8,394
Reputation: 113,482

Post » Tue Sep 16, 2014 5:13 pm

Thanks @newt, had to adjust a little bit to get the expected results but the logic worked for me
Please tag me with @caiorosisca if your post is refering to me :). I don't always follow the topics I answer.
B
11
S
4
G
1
Posts: 272
Reputation: 1,643


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 21 guests