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
Post a Comment