Replace a (n-1) character with another character

Hi,

I would like to replace the word as following, input is a string

input

4.098.63
1.145.678.45

output

4,098.63
1,145,678.45

Thank you

Hi @Naga_Abhishek_Reddy_Chepp,

Please try

input.Replace(“,”, “.”)

thanks for the reply, but i donot want all the ‘.’ to be replaced with ‘,’. it is a currency value

@Naga_Abhishek_Reddy_Chepp

Sorry, my mistake.
Taking your input, the comma needs to be placed for every 7th element+, counting from the end of string, which is dot.
Try this code please.

output = input.Substring(0,input.Length-6).Replace(“.”, “,”) + input.Substring(input.Length-6, 6)

image

Hi @Naga_Abhishek_Reddy_Chepp ,

Check with the below Expression :

(new Regex(Regex.Escape("."))).Replace("4.098.63",",",Regex.Matches("4.098.63","\.").Count-1)

image

Instead of the hardcoded string, you could place your String variable.

Let us know if it does not work.

if the length is not greater than then it will throw error

Hi,

How about the following expression?

System.Text.RegularExpressions.Regex.Replace(yourString,"(?<=\d+)(\.\d+)+(?=\.\d+)",Function(m) m.Value.Replace(".",","))

Regards,

HI @Naga_Abhishek_Reddy_Chepp

Check this expression

YourString.Replace(".",",").Substring(0,YourString.LastIndexOf("."))+YourString.Substring(YourString.LastIndexOf("."))


Regards
Sudharsan

Regards
Sudharsan

Thank you, it worked

image

Actually, i have a datatable with contains currency column that needs to be validated and remove the ‘.’ and replace with ‘,’ as above stated, is there any linq query to do that. Instead of iterating and using regex to to the same?

@Naga_Abhishek_Reddy_Chepp ,

If it is an Update operation that you would want to perform, it would be better to first check with the For Each Row Activity itself, if you do think the performance is slow, Maybe we could try with an alternate Linq approach and check it’s performance and compare.

It would be better to post a Separate Topic on it as the Topic here is resolved based on your Initial requirement.

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