《急》C#字符串问题

来源:百度知道 编辑:UC知道 时间:2024/06/01 01:18:22
一种类型的字符串格式如下
strng str="A;B;C;D;E;FQW;"
分号为分隔符
把分号之间的字符串提取出来放进一个List<Stirng>中
上面的str提取出来的就是 A B C D E FQW 6个字符串
最好用For循环
哪位大侠能给个算法 不胜感激

string str_temp = string.Empty;
int n = 0;
foreach (char c in str)
{
if (c.Equals(';'))
{
//在这里将str_temp添加到你的List<Stirng>中,n为序列号
str_temp = string.Empty;
n++;
}
else
{
str_temp += c.ToString();
}
}

过了五一再说

split不行吗?非用for循环?

string str = "A;B;C;D;E;FQW;";
string [] split = str.Split(new Char [] {';'});
干嘛要有for那么麻烦啊?

//用正则表达式来拆分字符串
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
string s = "cd;sd