I have a list as a single string like - "['2','4','5','1']" and length of this is 17 as each char is counted.
Now I want to parse it into list object like - ['2','4','5','1'] whose length will be 4 as the number of elements in a list.
How can I do this in C#?
Can it be done without doing basic string operations? If yes then how?
list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<char>>("['2','4','5','1']");var result = str.Split(',','[',']').Where(s => !string.IsNullOrEmpty(s)).ToList();StringSplitOptions.RemoveEmptyEntries- don't know if there's a difference in performance, but I'd rather use the option.var result = str.Split(new[] { ',','[',']' }, StringSplitOptions.RemoveEmptyEntries);