I have a String like
If i am using Trim Method means, It will trim Left and Right empty Space…
But using Trim Method, the output will comes like this
But i want to trim the in-between string…like this
How can i achieve this…???
I have a String like
If i am using Trim Method means, It will trim Left and Right empty Space…
But using Trim Method, the output will comes like this
But i want to trim the in-between string…like this
How can i achieve this…???
Hey @Poovarasan2
you can use Regex to replace space .
Regex.Replace(“your_str”, “\s+”, “”);
or
you can use string.replace as well to replace space with “”.
Regards…!!
Aksh
Hi,
I hope this will helpful to you…
regex.Replace(str,“\s{2,}”," ")
Regards,
string.replace will not work if string contains more than two space as it will loop only once for whole string, say if string is “abc(four space)def” then string.replace will remove only two space, the result will be (“abc(two space)def”).
I was talking about string.replace…
regex.replace definitely gonna work but not this Regex.Replace(“your_str”, “\s+”, “”) but this Regex.Replace(“your_str”, “\s+”, “ ”)
Hey @AkshaySandhu
I have mention the alternate option to use it i have not said that string.replace(" ",String.Empty) you are getting right it will replace one space.or if you will pass two space then also it will replace those.
For your information Either you can loop it for example while and check how much space that string contains then remove all with single space then fire your string replacement.
My bad at the time of posting… my level of undersating was different and thought the same understanding for whom i was posting.
this way as well without loop kind of hard coded
str.Replace(" "," ").Replace(" "," ").Replace(" "," ").Replace(" "," ")
// replace chaining with 1 space, 2 space, 3 space, 4 space
Regards…!!
Aksh
I have a Excel header in the Format like " Country Code * ".
But i need the Output as " Country Code ".
without Special Character (*) ? how to Remove Special Character.