1

If i have string like that:

string s = "xzy...";

how to convert it to array like that:

string[] ss = {"x", "z", "y", ...}

2 Answers 2

6

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())
Sign up to request clarification or add additional context in comments.

1 Comment

I knew that there is method s.ToCharArray() but didn't know how to convert it to string array just using just one line of code.
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.