0

How do you convert string to Char Array in C#?

I tried with the ToCharArray method but it seems it doesn't work

11th Mar 2020, 6:14 PM
HadexGM
8 Answers
+ 1
There must be a function for that.. May be syntax issue with your ToCharArray(). But otherthan, as a temporary solution, as simple alternative also you can use foreach loop, like foreach (var ss in stringA) s[i++]=ss; Here, stringA is string s[] is char array.. Edit: Yes. It also works string sentence = "hello world"; char[] cArray= sentence.ToCharArray(); foreach (char ch in cArray) Console.WriteLine(ch);
11th Mar 2020, 6:49 PM
Jayakrishna 🇼🇳
+ 1
~ swim ~ i was trying this for a code coach but i'll try it with your code now using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { string s = "Hello World"; s.ToCharArray(); Array.Reverse(s); Console.WriteLine(s); } } }
11th Mar 2020, 7:09 PM
HadexGM
+ 1
11th Mar 2020, 7:23 PM
HadexGM
+ 1
Use ToCharArray() or string.Split() function
13th Mar 2020, 11:50 AM
Mufungo Geeks
Mufungo Geeks - avatar
0
AI-Virar does String.Split() exist in C#?
17th Mar 2020, 4:00 AM
HadexGM
0
HadexGM yes it does
17th Mar 2020, 9:22 AM
Mufungo Geeks
Mufungo Geeks - avatar