How to replace the value at specific position in var

Get help using Construct 2

Post » Sat Oct 07, 2017 2:45 pm

Hi guys, I have a small newbie question. I have a variable = "a,b,c,a,d,f" and I have to replace the value at position 4 (comma as a separator, in this case it is "a") to something else. How to make it?
I'm pretty sure this was discussed, but I can't find it...
Thanks in advance! :?
ImageImageImage
B
47
S
18
G
3
Posts: 164
Reputation: 5,336

Post » Sat Oct 07, 2017 3:44 pm

Something like this maybe?
Image

It can probably be done easier with regular expressions, but I don't know them that well (or in fact at all :) )
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :)
B
17
S
9
G
69
Posts: 1,048
Reputation: 37,659

Post » Sat Oct 07, 2017 3:58 pm

dop2000 wrote:Something like this maybe?
Image

It can probably be done easier with regular expressions, but I don't know them that well (or in fact at all :) )


:lol: :lol: :lol: I was thinking about something like this, and it's really can be made by looping in the new avr etc. But like you mentioned, there have to be a more rational way to made it by Regex. But but I don't know them too.
ImageImageImage
B
47
S
18
G
3
Posts: 164
Reputation: 5,336

Post » Sun Oct 08, 2017 9:40 am

Ok, I read a few beginners tutorials on regular expressions and apparently you can parse comma-separated strings with a simple pattern like this:
Code: Select all
(?<=\r|\n|^)(?!\r|\n|$)(?:(?:"(?<Value>(?:[^"]|"")*)"|(?<Value>(?!")[^,\r\n]+)|"(?<OpenValue>(?:[^"]|"")*)(?=\r|\n|$)|(?<Value>))(?:,|(?=\r|\n|$)))+?(?:(?<=,)(?<Value>))?(?:\r\n|\r|\n|$)

Easy-peasy! :)
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :)
B
17
S
9
G
69
Posts: 1,048
Reputation: 37,659

Post » Sun Oct 08, 2017 2:32 pm

dop2000 wrote:Easy-peasy! :)


oh man :o ... maybe you can give me simple example on https://regex101.com/ or something like that?

I really thank you.
ImageImageImage
B
47
S
18
G
3
Posts: 164
Reputation: 5,336

Post » Sun Oct 08, 2017 3:06 pm

That was a joke :)
I did some googling and turned out that parsing comma-separated strings with regex is quite a difficult task. So I copy-pasted that pattern from stackoverflow :)
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :)
B
17
S
9
G
69
Posts: 1,048
Reputation: 37,659

Post » Sun Oct 08, 2017 4:47 pm

dop2000 wrote:That was a joke :)

:lol: :lol: :lol:

Ok, now I think there is no way to perform it without using some cyclic operation... So the "tokenat & looping" method may be a decent decision or I will use array instead of var. Anyway thanx :D
ImageImageImage
B
47
S
18
G
3
Posts: 164
Reputation: 5,336


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 13 guests