日期:2014-05-17  浏览次数:20446 次

WebService返回string字符串截取

航信接口返回过来的参数
例如第一条2011-5-1,0730,0940,CA,1831,F9A0P0J9Y9B9M9H9K0L0Q0G0S9N0V9W9T9E0*9,T3|T2,PEK,SHA,333,0,1,0,1,DS,M19V19
5月1号的航班,7.30出发 9.40到达 所属航空公司:CA 航班号:1831 杭楼:。。。 
<?xml version="1.0" encoding="utf-8" ?> 
<string xmlns="http://tempuri.org/">
2011-5-1,0730,0940,CA,1831,F9A0P0J9Y9B9M9H9K0L0Q0G0S9N0V9W9T9E0*9,T3|T2,PEK,SHA,333,0,1,0,1,DS,M19V19^
2011-5-1,0745,0950,CA,1883,F5A0P0Y9B9M9H9K0L0Q0G0S9N0V9W9T9E0*9,T3|T2,PEK,PVG,738,0,1,0,1,DS,M19V19^
2011-5-1,0830,1040,CA,1501,F9A0P0C9D0Z0R0Y9B9M9H9K0L0Q0G0S9N0V9W9T9E0*9,T3|T2,PEK,SHA,777,0,1,0,1,DS,M19V19^
2011-5-1,0930,1140,CA,1519,F9A0P0Y9B9M9H9K0L0Q0G0S9N0V9W9T9E0*9,T3|T2,PEK,SHA,330,0,0,0,1,DS,M19V19^2011-5-1,1130,1340,CA,1557,F9A0P0J9Y9B9M9H9K0L0Q0G0S9N0V9W9T9E0*9,T3|T2,PEK,SHA,333,0,1,0,1,DS,M19V19^2011-5-1,1330,1540,CA,1517,F9A0P0Y9B9M9H9K0L0Q0G0S9N0V9W9T9E0*9,T3|T2,PEK,SHA,767,0,1,0,1,DS,M19V19^2011-5-1,1400,1605,CA,934,F8A0P0C9D0Z0R0Y9B0M0H0K0L0Q0G0S9N0V0U0W9T0E0*9,T3|T2,PEK,PVG,340,0,1,0,1,DS,M10V10^2011-5-1,1430,1640,CA,1521,F9A0P0J9Y9B9M9H9K0L0Q0G0S9N0V9W9T9E0*9,T3|T2,PEK,SHA,333,0,0,0,1,DS,M19V19^2011-5-1,1530,1740,CA,1515,F9A0P0Y9B9M9H9K0L0Q0G0S9N0V9W9T9E0*9,T3|T2,PEK,SHA,772,0,0,0,1,DS,M19V19^2011-5-1,1600,1810,CA,175,C9D0Z0R0Y9B0M0H0K0L0Q0G0S7N0V0U0W0T0E0*9,T3|T2,PEK,PVG,330,0,0,0,1,DS,M10V10^2011-5-1,1630,1840,CA,1549,F9A0P0Y9B9M9H9K0L0Q0G0S9N0V5W9T9E0*9,T3|T2,PEK,SHA,330,0,0,0,1,DS,M19V15^2011-5-1,1730,1940,CA,1855,F9A0P0Y9B9M9H9K0L0Q0G0S9N0V9W9T9E0*9,T3|T2,PEK,SHA,772,0,1,0,1,DS,M19V19^2011-5-1,1830,2040,CA,1995,F9A0P0J9Y9B9M9H9K0L0Q0G0S9N0V5W9T9E0*9,T3|T2,PEK,SHA,333,0,1,0,1,DS,M19V15^2011-5-1,1945,2155,CA,1857,F9A0P0J9Y9B9M9H9K0L0Q0G0S9N0V9W9T9E0*9,T3|T2,PEK,SHA,333,0,1,0,1,DS,M19V19^2011-5-1,2000,2215,CA,986,F8A0P0C9D9Z7R2Y9B0M0H0K0L0Q0G0S7N0V0U0W0T0E0*9,T3|T2,PEK,PVG,340,0,1,0,1,DS,M10V10^2011-5-1,2030,2240,CA,1589,F6A0P0Y9B9M9H9K0L0Q0G0S9N0V9W9T9E9*9,T3|T2,PEK,SHA,738,0,0,0,1,DS,M19V19
</string> 
[^]为一条信息的结尾,问怎么分割啊 按照逗号进行截取


------解决方案--------------------
取得<string>节点的值,先split("^"),每个元素split(",")
------解决方案--------------------
C# code
 string str = "2011-5-1,0730,0940,CA,1831,F9A0P0J9Y9B9M9H9K0L0Q0G0S9N0V9W9T9E0*9,T3|T2,PEK,SHA,333,0,1,0,1,DS,M19V195月1号的航班,";
            string[] newstr = str.Split(',');
            for (int i = 0; i < newstr.Length; i++)
            {
                Response.Write(newstr[i].ToString()+"<br/>");
            }

------解决方案--------------------
思路:
1、根据 xml 获得 所有信息 
2、根据 [^] 进行分割
3、根据 [,] 进行分割
代码:
C# code

//----xmlStr 返回来的字符串
 //如果 是想保存到集合的话: 建立一个List集合和 对象进行存储 
 //List<信息类> list = new List<信息类>;
 XmlDocument xmlDoc = new XmlDocument();
 xmlDoc.LoadXml(xmlStr);
 String allStr = xmlDoc.SelectSingleNode("string").InnerText;
 froeach(String str in allStr.Split('^'))
 {
      froeach(String strs in str.Split(','))
      {
          //信息类 tmp = new 信息类;
         //--- 取出所有信息 2011-5-1,0730,0940,CA,1831,F9A0P0J9Y9B9M9H9K0L0Q0G0S9N0V9W9T9E0*9,T3|T2,PEK,SHA,333,0,1,0,1,DS,M19V19
         // 对信息类进行相应赋值 
         // list.add(tmp);       
 
      }
 }

------解决方案--------------------
探讨

思路:
1、根据 xml 获得 所有信息
2、根据 [^] 进行分割
3、根据 [,] 进行分割
代码:
C# code

//----xmlStr 返回来的字符串
//如果 是想保存到集合的话: 建立一个List集合和 对象进行存储
//List<信息类> list = new List<信息类>;
XmlDocument xmlDoc = new XmlDocument……

------解决方案--------------------
探讨

引用: