I’m using Regex.Split() to take the user input and turn it into individual words in a list but at the moment it removes any spaces they add, I would like it to keep the whitespace.
string[] newInput = Regex.Split(updatedLine, @"\s+");
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This will give you 4 splits each having all the leading spaces preserved.
Means split from the point where there are spaces ahead. But if you use this alone it will create 15 splits on the sample text because every space is followed by another space in case of repeated spaces.
This means split from a point which has non space character before it and it has spaces ahead of it.
If the text starts from a space and you want that to be captured in first split with no text then you can modify the expression to following
Which means series of spaces need to have a non space character before it OR start of the string.