I have text. for example string text = "COMPUTER"
And I want to split it into characters, to keep every character as string.
If there were any delimiter I can use text.Split(delimiter).
But there is not any delimiter, I convert it to char array with
text.ToCharArray().toList().
And after that I get List<char>. But I need List<string>.
So How can I convert List<char> to List<string>.
Add a comment
|
6 Answers
try this
var result = input.Select(c => c.ToString()).ToList();
3 Comments
knittl
@Ripple: because the answer has been edited since (but still within the initial "historyless" time window). The original answer had nothing to do with the question
varsha
thank you @Ripple and knittl for being fair , I was mistaken in getting the question in hurry and I'm sorry for that
knittl
@Ripple: I cannot remove the upvote, because the edit does not show up as edit. Upvotes can only be removed after a (real) edit was made.
string bla = "COMPUTER"; //Your String
List<char> list = bla.ToCharArray().ToList(); //Your char list
List<string> otherList = new List<string>(); //Your string list
list.ForEach(c => otherList.Add(c.ToString())); //iterate through char-list convert every char to string and add it to your string list