c# - Split Line with Two Delimiters -
context
i'm designing application bring in initial settings application use. settings imported through text file , have format:
color= blue size= 5 value = 100 each line created object setting(string a, string b) using delimiter of "=" line.split(). each object created added list(setting) _settingslist.
problem
there 2 settings @ end of text file in format
location = 123 street, city, state, zip code in situation, want split both "=" , "," , use create object location(string name, string address, string city, string state, string zip). finally, added list _loclist.
current code
streamreader reader = new streamreader(openfiledialog1.filename); string line; while ((line = reader.readline()) != null) { string[] words = line.split('='); if(words[0].tolower().trim() == "location") { string keepthis = words[0].tolower().trim(); string[] words = line.split('='); //how split 2 delimiters? _loclist.add(new location(words[0], words[1], words[2], words[3], words[4]); } _settingslist.add(new setting(words[0], words[1])); } the string keepthis there because tried remove entire "location = " part line, use "," delimiter, add new location(keep this, words[0], words[1], words[2], words[3])
any suggestions solve appreciated!
string[] words = line.split('=', ','); use , should good. close. can add many parameters want .split() include many escape chars needed. tip though, if you're ever using 3 or more escape characters i'd suggest making array of them first, passing array argument. keeps clean!
hope helps bud!
Comments
Post a Comment