1

If i have string like that:

string s = "xzy...";

how to convert it to array like that:

string[] ss = {"x", "z", "y", ...}
vcsjones
142k34 gold badges301 silver badges295 bronze badges
asked Jul 26, 2011 at 0:35

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())
Yuriy Faktorovich
68.9k14 gold badges107 silver badges150 bronze badges
answered Jul 26, 2011 at 0:38
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()
answered Jul 26, 2011 at 0:40

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.