How to convert string into string array
If i have string like that:
string s = "xzy...";
how to convert it to array like that:
开发者_开发百科string[] ss = {"x", "z", "y", ...}
You're looking for ToCharArray()
.
This returns an array of char
s.
If you really need an array of string
s, you can write
Array.ConvertAll(s.ToCharArray(), c => c.ToString())
If you'd like to convert it to an array of characters you can use
s.ToCharArray();
But note that it already implements IEnumerable<char>
and has an indexer by position. If you really need strings
s.Select(c => c.ToString()).ToArray()
精彩评论