Replace single space with a double space

I have some data in a string with multiple words. I want to replace single space with two spaces at a particular place for eg:
str: “MOORESVILLE IN 46158 7403”
output str: “MOORESVILLE IN 46158 7403”

In output there are two spaces between IN and 46158 in the output string.

Hi @Vaibhav_Gupta,

Use below code to replace single space with double space

var.Replace("<singleSpace>","<doubleSpace>")

Better as
var.Replace("IN ","IN ")

Hi,

Is there any rule about replacing a space with double space such as after IN, between IN and number etc?

Regards,

IN is not fixed and could be any two digits

Yes as per my requirement i need to have two spaces between State code in this case IN and Zip Code

Hi,

Can you try the following?

strOut = System.Text.RegularExpressions.Regex.Replace(strIn,"(?<=[A-Z]{2}) (?=\d{5})","  ")

Regards,

1 Like

System.Text.RegularExpressions.Regex.Replace(“your string IN 4”,“(?<=IN).”," ")

Thanks, it worked

1 Like

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