How do I check for adjacent characters and if they match, delete one?

for example, i have next string “34499AAQQQ431” and i need sequentially check the characters one by one and if, for example, 22, then delete one of the character

Hi,

Can you try my post in your previous topic? I think it will work as you expect.

Regards,

What is the output for this character? @Vlad_Svitelskyi

349AQ431 like this, but it must be universal, different string with same result. we have 1rr33hh33, and checkk previous symbol and compare, when it the same delete one of this

Have you check the above thread in the @Yoichi post @Vlad_Svitelskyi

yes. maybe it possible to do this with for each?@Gokul001

Where did this input data will comes from? @Vlad_Svitelskyi, Like from an excel file

no, manually in assign for example ,enter in studio and it delete same symbol as previous

May be, it is not able to do via for each activity @Vlad_Svitelskyi

Not able to understand your requirement

Regards
Gokul

for example, i have 2 variables with next data “34499AAQQQ431”, “122qqe3312qe3” and i need to delete previous character when it the same as next character

Output for this string?

349AQ431, 12qe312qe3

Hi @Vlad_Svitelskyi

Check out the XAML file

Remove DuplicateCharacter.xaml (11.4 KB)

image

Regards
Gokul

1 Like

thank you so much

Hello, I had used the Invoke Code activity and called a VB.NET method.
The code of this method might look like this:

Dim i As Integer, n As Integer
Dim key As String, str As String

n = arg1.Length - 1
For i = n To 1 Step -1
If (arg1.Chars(i) = arg1.Chars(i - 1)) Then
str = arg1.Chars(i)
key = str + str
Do While (arg1.Contains(key))
arg1 = System.Text.RegularExpressions.Regex.Replace(arg1, key, str)
n = arg1.Length - 1
i = n
Loop
End If
Next i

result = arg1
''System.Windows.Forms.MessageBox.Show("Argument_1 = " + Chr(34) + result + Chr(34))

After setting the arguments, it could be added this code
arg1 is a String input argument and result is the output argument.
After deleting some characters the length of the string changes.
And the search may begin again from the end of the string.
Hope this is also a good method.
With fine regards, Adrian

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.