Rade Milovic
Rade Milovic

Reputation: 1015

Removing some characters from string using Regex

I'm using the following regex:

documentText = Regex.Replace(documentText, "\\\\|\\^|\\+|\\*|~|#|=|\"", "");

and it works. But when I split this string by using:

wordsInText = documentText.ToLower().Split(' ').ToList();

I get elements that are marked as "" (empty string). I can remove it manually by iterating through collection and removing empty elements, but it must be a way to prevent this weird behaviour.

Upvotes: 1

Views: 128

Answers (1)

L.B
L.B

Reputation: 116108

documentText.ToLower().Split(new char[]{' '},StringSplitOptions.RemoveEmptyEntries)

Upvotes: 1

Related Questions