简体   繁体   中英

is it possible to compare char from string with set of chars?

during parsing string I want to make decision when to stop and go to get next portion from string. My main goal is to take 3 portions of string 26 or less chars length. My code seems to me a little weird

for (basis=i*26; basis<name.Length
                    && name[basis] != ' '
                    && name[basis] != '-'
                    && name[basis] != '('
                    && name[basis] != ')'
                    && name[basis] != ';'
                    && name[basis] != ','
                    && name[basis] != '.'
                    && name[basis] != '"';
            basis--) ;

You should be able to use a Set:

var excludes = new HashSet<Char> { ' ', '-', ... };

Then test if your character is in the set with

excludes.contains(someChar)

Set docs

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