Replace character without pattern

Hello

I’m trying to give a replace on a non-standard character. Example:

In my txt file, I want to replace the value “A” with the value “B”

The problem is that the value “A” can be “AAA” or “AAAA …”
There is no “A” quantity pattern.

I made use of the “Replace Text” activity, I did not succeed.

Can you help me?

Thank you.

Is there a maximum number of A’s that would ever occur in the string? I’m thinking if there will never be more than let’s say 10 A’s, we could substitute AAAAAAAAAA(10) with B, then again AAAAAAAAA(9) with B, all the way down to 1.

Yes, there is maximum number: 30

And by using assign activities with : new string" = Yourstring.replace(“a”, “b”), it’s that better then used the activitie?

1 Like

Yes and instead of having to create 30 separate assign or replace activities you could use a do while with a counter which also specifies the number of characters (which match the counter variable). It would just need to count down from 30. You could just replace left(string, countervariable) with B.

1 Like

Can you send a simple example in xaml?

1 Like

Hi.

I found a simple way to specify the count in your Replace:

Strings.Replace(str, "A", "B", 1, 1)

where the second “1” is the count.

You can use this in an Assign activity.

Depending on your other requirements, you can also find the index to use as your “Start” so skip certain characters if you want.

3 Likes

@ClaytonM is right. I’ve attached the xaml for your reference though.

ReplaceChar.zip (10.1 KB)

2 Likes

@fernandoborges, use a string method. For exemple, a variable text of type string. Then you have to use the assign activity: text = text.Replace(“A”,“B”).

You can also use a regex option and Matches activity. According to your purpose, the solution of using a string is quicker and simpler.

1 Like

Hello guys

Thanks to all the answers.

I solved with the replace activity, using Regex: “\ A +”

Dear @fernandoborges, Can you share an example ?