Remove all whitespace from C# string with regex -


i building string of last names separated hyphens. whitespace gets caught in there. need remove whitespace end result.

sample string work on:

anderson -reed-smith

it needs end (no space after anderson):

anderson-reed-smith

the last name string in string variable, lastname.

i using regular expression:

regex.replace(lastname, @"[\s+]", ""); 

the result of is:

anderson -reed-smith.

i tried:

regex.replace(lastname, @"\s+", ""); 

and

regex.replace(lastname, @"\s", ""); 

what doing wrong?

instead of regex use replace simple:

lastname = lastname.replace(" ", string.empty); 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -