using System; using System.Collections.Generic; using System.Text;namespace ConsoleApplication2 { class Program { static void Main(string[] args) { string str = "adkfj;laskdg;lhqoiwuerioweutkli"; int strlen = str.Length; string[] s = new string[strlen]; for (int i = 0; i < strlen; i++) { s[i] =str.Substring(i,1); } for (int i = 0; i < s.Length; i++) { Console.WriteLine(s[i]); } Console.ReadLine(); } } }
using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { string str = "adkfj;laskdg;lhqoiwuerioweutkli"; int strlen = str.Length; string[] s = new string[strlen]; for (int i = 0; i < strlen; i++) { s[i] =str.Substring(i,1); } for (int i = 0; i < s.Length; i++) { Console.WriteLine(s[i]); } Console.ReadLine(); } } }
string[] sArray = str.Split(',');参数是分隔符,也可以有多个。
string s = "abcd1234"; char[] charArray = s.ToCharArray();
这个是错误的,不好意思写错了正确的是string.ToCharArray()
ToCharArray()
public class StringSplit2 {
public static void Main() { string delimStr = " ,.:";
char [] delimiter = delimStr.ToCharArray();
string words = "one two,three:four.";
string [] split = null; Console.WriteLine("The delimiters are -{0}-", delimStr);
for (int x = 1; x <= 5; x++) {
split = words.Split(delimiter, x);
Console.WriteLine("\ncount = {0,2} ..............", x);
foreach (string s in split) {
Console.WriteLine("-{0}-", s);
}
}
}
}
例如
"abc"[0] 表示a
string.ToCharArray() 返回的就是 char[] 数组了,要把它放到其它数组变量中的话就用数组的 CopyTo() 好了
using System.Collections.Generic;
using System.Text;namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string str = "adkfj;laskdg;lhqoiwuerioweutkli";
int strlen = str.Length;
string[] s = new string[strlen];
for (int i = 0; i < strlen; i++)
{
s[i] =str.Substring(i,1);
}
for (int i = 0; i < s.Length; i++)
{
Console.WriteLine(s[i]);
}
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.Text; namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string str = "adkfj;laskdg;lhqoiwuerioweutkli";
int strlen = str.Length;
string[] s = new string[strlen];
for (int i = 0; i < strlen; i++)
{
s[i] =str.Substring(i,1);
}
for (int i = 0; i < s.Length; i++)
{
Console.WriteLine(s[i]);
}
Console.ReadLine();
}
}
}
char[] charArray = s.ToCharArray();