Joper
Joper

Reputation: 8219

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", ...}

Upvotes: 1

Views: 627

Answers (2)

SLaks
SLaks

Reputation: 888107

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())

Upvotes: 6

Yuriy Faktorovich
Yuriy Faktorovich

Reputation: 68737

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()

Upvotes: 1

Related Questions