For each String length - Loop over by indices

Hello! I am new to Uipath and looking for a way to loop over string indices. I am trying to find the characters in two strings (str1, str2) that appear in the same position.

Ex: Str 1 = 1234
Str 2 = 4334

I would like to do this via below approach
for i = 0 to string.length

if Str1[i] = str2[i]

print(“Match” )


print(“Not match”)

Can you please let me know how can I achieve this using For each in Uipath? What should be the Type Argument?

Any help would be highly appreciated.

It may be simpler to use a while loop for this.

Start with i=0

While i < string.length

if Str1[i] = str2[i]
writeline(“Not match”)

assign i = i+1

that should do what you need it to

To use a ForEach, you need to use .ToCharArray on the string, like ForEach chr1 In str1.ToCharArray
The 2018.4 version should give you the property for iteration number, which you can use in the second string. Or use a counter if not.

ForEach chr1 In str1.ToCharArray
    If chr1 = str2(i)

I normally try to avoid Do While loops using counters, but that would work too if you choose.

1 Like