简体   繁体   中英

one long string => array/list<string> from text within quotes

3>>asdf3424"THIS TEXT".,.<<<>>3asfdf"THISTOO"6575tsdfbxbxcv"ANDTHIS",,p-01fa

To an array or list of { "THIS TEXT", "THISTOO, "ANDTHIS" }

Does anyone have an idea on how to efficiently do this?

var result = Regex.Matches(input, @"\"".+?\""")
             .Cast<Match>()
             .Select(m => m.Value)
             .ToArray();

If you read each character at a time and look for a quotation mark, then read the following into a char array until you find a another quotation mark, then continue looking for one, you can have a list of char arrays that are easily transferable to string.

It should just be a simple while(still characters to be read).

If you have some big string maybe like this :

string str = "hello,hi,bye";

you may split it by comma something like this:

string[] breakups = str.Split(new[] {',' });

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