Changing Specific Data From a Text Variable

I want the text in a variable (dictated by the text input by the user) to be encoded. For example, every instance of “a” becomes “0”, every instance of “b” becomes “1”, etc.

How do I change specific letters, numbers, and symbols in a variable with multiple different data pieces (i.e. a sentence)?

1 Like

what happens when you get to 10? do you replace the letters with 2 digit numbers? Seems like you would be better creating an array of numbers and then changing them according to the text in a String

Check out this Regular Expressions behavior. It has an expression that replaces a patten in a string RegEx::Replace(). So to replace every letter “a”, you can use this expression to search for “a” in the string and replace it with “0”. But this only works one time once it finds the first letter “a”. So you need to repeat this for every letter in the string. You can put the actions in a repeat event.

Repeat StrLength(StringVar) times:

  • change the variable StringVar to: RegEx::Replace(“a”, “”, StringVar, “0”)
  • … RegEx::Replace(“b”, “”, StringVar, “1”)
  • … RegEx::Replace(“some string”, “”, StringVar, “another string”)

You could create a translation array and text each character, then add the conversion to a new variable:

The translation array could look like this:

i repeated 36 times to represent a-z + 0-9 possible input characters