using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.ComponentModel;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
string str = “Technical;T_REU~!@#$%^&*()_+SEF_900;”Reuse factor; 900″;Number;1;Reuse factor 900”;//示例字符串
ArrayList temp = new ArrayList();
ArrayList chartemp = new ArrayList();
Boolean abort = false;
int count = 0;
int count2 =0;
foreach (char i in str)
{
if (i.Equals(‘”‘)) {
abort = !abort;
}
if (!i.Equals(‘”‘)&&!i.Equals(‘;’)) {
chartemp.Add(i);
}
if (!i.Equals(‘”‘) && i.Equals(‘;’)&&abort==true)
{
chartemp.Add(i);
}
if (i.Equals(‘;’)&&abort==false) {
string str5 = string.Join(null,(char[])chartemp.ToArray(typeof(char))); //其实这句是核心
temp.Add(str5);
chartemp.Clear();
}
}
string str6 = string.Join(null, (char[])chartemp.ToArray(typeof(char)));
temp.Add(str6);
chartemp.Clear();
foreach ( var i in temp) {
Console.WriteLine(i);
}
Console.ReadLine();
}
}
}
C#分割字符串且忽略引号内
最新推荐文章于 2024-01-18 09:57:38 发布