字符串:[SID]:[TID]@[TkPara]#[TID]@[TkPara]#[TID]@[TkPara]....$[SID]:[TID]@[TkPara]#[TID]@[TkPara]#[TID]@[TkPara]#...$[SID]:[TID]@[TkPara]#[TID]@[TkPara]#[TID]@[TkPara]#...
例子:
string="a:2@P=12;J=13;V=14;O=15;A=16;D=17;#3@P=19;J=20;V=21;O=22;A=23;D=24;......#b:3@P=31;J=32;V=33;O=34;A=35;D=36;#4@P=37;J=38;V=39;O=40;A=41;D=42;...#c:4@P=51;J=52;V=53;O=54;A=55;D=56;#3@P=61;J=62;V=63;O=64;A=65;D=66;"
如何组合成书数组:
{(a,2,12,13,14,15,16,17),(a,3,19,20,21,22,23,24),...(b,3,31,32,33,34,35,36),(b,4,37,38,39,40,41,42),...(c,4,51,52,53,54,55,56),...}
例子:
string="a:2@P=12;J=13;V=14;O=15;A=16;D=17;#3@P=19;J=20;V=21;O=22;A=23;D=24;......#b:3@P=31;J=32;V=33;O=34;A=35;D=36;#4@P=37;J=38;V=39;O=40;A=41;D=42;...#c:4@P=51;J=52;V=53;O=54;A=55;D=56;#3@P=61;J=62;V=63;O=64;A=65;D=66;"
如何组合成书数组:
{(a,2,12,13,14,15,16,17),(a,3,19,20,21,22,23,24),...(b,3,31,32,33,34,35,36),(b,4,37,38,39,40,41,42),...(c,4,51,52,53,54,55,56),...}
str=str.Replace("@",";");
string[] strTemps=str.Split('#');
string strT="";
ArrayList al=new ArrayList();
foreach(string s in strTemps)
{
int i=s.IndexOf(':');
if(i>-1)
strT=s.Substring(0,i);
string st=Regex.Replace(s,@"[^\d\;]","");
st=st.Substring(0,st.Length-1);
st=strT+";"+st;
al.Add(st.Split(';'));
}
string[][] strR=(string[][])al.ToArray(typeof(string[]));
//用着玩
一层一层的分析。就出来了。一层一层的处理,就简单了。string strTarget="a:2@P=12;J=13;V=14;O=15;A=16;D=17;#3@P=19;J=20;V=21;O=22;A=23;D=24;......#b:3@P=31;J=32;V=33;O=34;A=35;D=36;#4@P=37;J=38;V=39;O=40;A=41;D=42;...#c:4@P=51;J=52;V=53;O=54;A=55;D=56;#3@P=61;J=62;V=63;O=64;A=65;D=66;";
string strKey1="#";
int intKey1=strTarget.IndexOf(strKey1); //key1表示#位置
int intKey2; //key2表示@位置
int intKey3; //表示“:”位置
int intKey4; //表示=号位置
int intKey5; //表示;位置
while(intKey1!=-1) //这个是第一层
{
string strTemp1=strTarget.Substring(0,intKey1); //裁减字符串
strTarget.Substring(intKey1,strTarget.Lengh-intKey1);//裁减字符串
//处理@
intKey2=strTemp1.IndexOf("@");
intKey3=strTemp1.IndexOf(":");
//第一个数字就在intKey2和Key3之间
int intResult=int.Parse(intTemp1.Substring(intKey3,intKey2-intKey3));
intKey4=strTemp.IndexOf("=");
while(intKey4!=-1) //这里是第二层
{
//其它的你就可以接着思路写了。
}
}
另外以上程序没有经过调试。只是表示一个解法思路。请LZ注意
我输出了一下,第二行有个小错误:
应该是24,不知道为什么取成了2:
2006-12-20 15:17:18 a;2;12;13;14;15;16;17
2006-12-20 15:17:18 a;3;19;20;21;22;23;2
2006-12-20 15:17:18 b;3;31;32;33;34;35;36
2006-12-20 15:17:18 b;4;37;38;39;40;41;42
2006-12-20 15:17:18 c;4;51;52;53;54;55;56
2006-12-20 15:17:18 c;3;61;62;63;64;65;66
msn: [email protected]
q q: 5985880
谢谢,揭贴
还有个问题,个别值加小数点后成这样了?
2006-12-20 15:28:07 a;2;12;13;14;15;16;1707
2006-12-20 15:28:07 a;3;1900;20;21;22;23;2401
2006-12-20 15:28:07 b;3;31;32;33;34;35;36
2006-12-20 15:28:07 b;4;37;38;39;40;41;42
2006-12-20 15:28:07 c;4;51;52;53;54;55;56
2006-12-20 15:28:07 c;3;61;62;63;64;65;6604