How to replace the value at specific position in var

0 favourites
  • 7 posts
  • 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!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Something like this maybe?

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

  • Something like this maybe?

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

    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.

  • Ok, I read a few beginners tutorials on regular expressions and apparently you can parse comma-separated strings with a simple pattern like this:

    (?<=\r|\n|^)(?!\r|\n|$)(?:(?:"(?<Value>(?:[^"]|"")*)"|(?<Value>(?!")[^,\r\n]+)|"(?<OpenValue>(?:[^"]|"")*)(?=\r|\n|$)|(?<Value>))(?:,|(?=\r|\n|$)))+?(?:(?<=,)(?<Value>))?(?:\r\n|\r|\n|$)[/code:2st6x3tn]
    Easy-peasy!
  • Easy-peasy! <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    oh man <img src="{SMILIES_PATH}/icon_e_surprised.gif" alt=":o" title="Surprised"> ... maybe you can give me simple example on https://regex101.com/ or something like that?

    I really thank you.

  • 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

  • That was a joke

    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

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)