[属性1]
参数=2210.3,12.65,115,25,420.66,445.69,0.569
[属性2]
9,0.018,2003-10,@
J01,1,3751508.5,39438683.65
J02,1,3751508.5,39438690.15
5,0.0247,2003-12,@
J01,1,3755389.7,39437380.2
怎样把属性1和属性2分离出来?属性一算是一段,属性2算是另一段,属性2中可能有多个以‘@’结尾的部分又需要分成多个小段。
我主要是想将txt分成3部分,一个是属性1和属性2之间的那一段,第二部分是以‘@’结尾的那一行到下一个以'@'结尾的那一行之前的那一段,就是示例 中的第4、5、6三行,第三部分就是之后的7、8两行,也就是和第二部分差不多的,要求要是有多个‘@’结尾的部分的话要求能分成多段。
不知道我说明白没有,不明白的一起讨论一下!
成果:
1 /// <summary>
2 /// Gets the ZD array.
3 /// </summary>
4 /// <param name="fileName">Name of the file.</param>
5 /// <returns></returns>
6 private ArrayList GetZDArray(string fileName)
7 {
8 //读取文件内容
9 StreamReader sr = new StreamReader(fileName, System.Text.Encoding.Default);
10 string tempStr = ""; //sr.ReadLine();
11 ArrayList ArrList = new ArrayList();
12 ArrayList csArrList = new ArrayList();
13 ArrayList dkArrList = new ArrayList();
14 ArrayList zbArrList = new ArrayList();
15
16 //初步整理文件内容并读出至ArrList中
17 while ((tempStr = sr.ReadLine()) != null)
18 {
19 tempStr = tempStr.Trim();
20 if (tempStr.Length < 1)
21 continue;
22 if (tempStr.IndexOf("[属性1]") == 0 ||tempStr.IndexOf("[属性2]") == 0)
23 {
24 continue;
25 }
26 else if (tempStr.Split('=').Length > 1)
27 {
28 csArrList.Add(tempStr);
29 }
30 else
31 {
32 dkArrList.Add(tempStr);
33 }
34 }
35 sr.Close();
36 ArrList.Add(csArrList);
37 ArrList.Add(dkArrList);
38 return ArrList;
39 }
40
41 /// <summary>
42 /// Gets the ZB STR from array.
43 /// </summary>
44 /// <param name="ArrList">The arr list.</param>
45 /// <returns></returns>
46 private string GetZBStrFromArray(ArrayList ArrList)
47 {
48 string dkstr = "";
49 string tem = "";
50 int spl = 0;
51 for (int i = 0; i < ArrList.Count; i++)
52 {
53 tem = (string)ArrList[i];
54 if (tem.Trim().Length < 1)
55 continue;
56 if (tem.Substring(tem.Length - 1, 1) == "@")
57 {
58 //continue;
59 spl++;
60 dkstr = dkstr + "#" + tem;
61 }
62 else
63 {
64 dkstr = dkstr + tem + "$";
65 }
66
67 }
68 return dkstr;
69 }
70 private bool InsertDKAndZB(string dkzbStr)
71 {
72 string[] dkandzb = dkzbStr.Split('#');
73 for (int i = 0; i < dkandzb.Length; i++)
74 {
75 string val1 = "";
76 if (dkandzb[i].Trim().Length < 1)
77 continue;
78 string[] dkStr = dkandzb[i].Split('@');
79 //dkStr 就是属性2中的一小段
80 }
81 }
2 /// Gets the ZD array.
3 /// </summary>
4 /// <param name="fileName">Name of the file.</param>
5 /// <returns></returns>
6 private ArrayList GetZDArray(string fileName)
7 {
8 //读取文件内容
9 StreamReader sr = new StreamReader(fileName, System.Text.Encoding.Default);
10 string tempStr = ""; //sr.ReadLine();
11 ArrayList ArrList = new ArrayList();
12 ArrayList csArrList = new ArrayList();
13 ArrayList dkArrList = new ArrayList();
14 ArrayList zbArrList = new ArrayList();
15
16 //初步整理文件内容并读出至ArrList中
17 while ((tempStr = sr.ReadLine()) != null)
18 {
19 tempStr = tempStr.Trim();
20 if (tempStr.Length < 1)
21 continue;
22 if (tempStr.IndexOf("[属性1]") == 0 ||tempStr.IndexOf("[属性2]") == 0)
23 {
24 continue;
25 }
26 else if (tempStr.Split('=').Length > 1)
27 {
28 csArrList.Add(tempStr);
29 }
30 else
31 {
32 dkArrList.Add(tempStr);
33 }
34 }
35 sr.Close();
36 ArrList.Add(csArrList);
37 ArrList.Add(dkArrList);
38 return ArrList;
39 }
40
41 /// <summary>
42 /// Gets the ZB STR from array.
43 /// </summary>
44 /// <param name="ArrList">The arr list.</param>
45 /// <returns></returns>
46 private string GetZBStrFromArray(ArrayList ArrList)
47 {
48 string dkstr = "";
49 string tem = "";
50 int spl = 0;
51 for (int i = 0; i < ArrList.Count; i++)
52 {
53 tem = (string)ArrList[i];
54 if (tem.Trim().Length < 1)
55 continue;
56 if (tem.Substring(tem.Length - 1, 1) == "@")
57 {
58 //continue;
59 spl++;
60 dkstr = dkstr + "#" + tem;
61 }
62 else
63 {
64 dkstr = dkstr + tem + "$";
65 }
66
67 }
68 return dkstr;
69 }
70 private bool InsertDKAndZB(string dkzbStr)
71 {
72 string[] dkandzb = dkzbStr.Split('#');
73 for (int i = 0; i < dkandzb.Length; i++)
74 {
75 string val1 = "";
76 if (dkandzb[i].Trim().Length < 1)
77 continue;
78 string[] dkStr = dkandzb[i].Split('@');
79 //dkStr 就是属性2中的一小段
80 }
81 }