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.
aanandsanraj
(Anandraj Rajendran)
January 13, 2020, 12:05pm
2
Hi @Vaibhav_Gupta ,
Use below code to replace single space with double space
var.Replace("<singleSpace>","<doubleSpace>")
Better as
var.Replace("IN ","IN ")
Yoichi
(Yoichi)
January 13, 2020, 12:14pm
4
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
Yoichi
(Yoichi)
January 13, 2020, 12:22pm
7
Hi,
Can you try the following?
strOut = System.Text.RegularExpressions.Regex.Replace(strIn,"(?<=[A-Z]{2}) (?=\d{5})"," ")
Regards,
1 Like
ashley11
(Ashley Nihal Dcunha)
January 13, 2020, 12:27pm
8
System.Text.RegularExpressions.Regex.Replace(“your string IN 4”,“(?<=IN).”," ")
system
(system)
Closed
January 16, 2020, 12:40pm
10
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.