I have a string that will have multiple whitespace characters in it and I’m wanting to seperate each word by 1 whitespace character. Say if the string is “Hi! My name is troy and i love waffles!”, I want to trim that so it is “Hi! My name is troy and I love waffles!”. How would I do this?
Share
Use the regular expression
\s+(one or more whitespace) with theRegex.Replacemethod from theSystem.Text.RegularExpressionsnamespace:If you just want to replace spaces you can change the “
\s” to a space ““: