开发者

How to convert string into string array

开发者 https://www.devze.com 2023-03-22 17:06 出处:网络
If i have string like that: string s = \"xzy...\"; how to convert it to array like that: 开发者_开发百科string[] ss = {\"x\", \"z\", \"y\", ...}

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

精彩评论

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