简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM