How to remove first dot(.) and replace with comma(,) in string like (121.006.891) when I have two dots(.)

Hi All,

Can someone help me in replacing the first dot(.) with comma(,) in string

Value1 = 121.006.891 → Want it to be like 121,006.891

Value 2 = 23.098.123 → Want it to be like 23,098.123

Value 3 = 19.123 → No need to change anything in this

→ I want to replace first dot with comma only when I have two dots in string.
→ No need to change anything when I have only one dot like (19.123)

Thanks,
Naresh

@Palaniyappan @ppr

Hi @Mandava_Naresh ,

Try this:

System.Text.RegularExpressions.Regex.Replace(InputString,"(\.)(?=\d+\.)",",")

image

Regards,

1 Like

here text will have your = 121.006.891

You can use the following expression:
First use this condition in an if statement:

text.Where(function (x) x=“.”).Count>1

Inside the then section use this:

newtext= text.Remove(text.IndexOf(“.”),1).Insert(text.IndexOf(“.”),“,”)

Thanks

we would have some doubts on the case as

  • When correctly formatted number strings the decimal and group separator are mixed up
  • a correct parsing and reformating with local culture info maybe a more prefered approach

However, we reformulated the case into:
remove all dots before the last dot

1 Like

Hi @Mandava_Naresh

You can use IF condition to check the count of the “.”

strValue.Where(function (val) val=“.”).Count > 1

In then you can place as below

strValue = strvalue.Substring(0, strValue.IndexOf(“.”)) & “,” & strValue.Substring(strValue.IndexOf(“.”) + 1)

Hope this may help you

Thanks,
Srini

1 Like

Thank you very much

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