I have a list that contains object with double quotes like this: " " (note the space between the quotes). I try to remove all those objects from the list but when I escape the quotes it still doesn't work.
The object is imported from a txt file as one string containing all information and then turned to an array which I export to a list to later use RemoveAll from.
Text txt file looks like this when I import it:
"" "Myadress 6" "151 33 City" ""
The imported result is stored in a string "importedData" and then I do like this to work with it:
string[] stringSeparators = new string[] { "\"" };
importedDataArray = importedData.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries);
var importedDataList = markupDataArray.ToList();
importedDataList.RemoveAll(item => item == "\" \"");
I'm interested to keep those objects that actually containing something, not the one with " ".
Right now the list contains 6 object of which 4 of them looks like " ".
Add simply a where clause condition in your line like that :
var importedDataList = markupDataArray
.Where(p => !string.IsNullOrWhiteSpace(item))
.ToList();
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.