开发者

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 chars.
If you really need an array of strings, 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()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜