XML源文件,这里仅仅是一个站点的信息:ServerBindings="61.142.208.162:80:ss.sschuangshida.com61.142.208.162:80:www.sschuangshida.com61.142.208.162:80:sschuangshida.com"这些是IIS里面导出的主机头值,排列顺序是这样:IP地址,端口,域名,怎么分割上面那段XML没有空格的字符串变成下面的效果
61.142.208.162   80   ss.sschuangshida.com
61.142.208.162   80   www.sschuangshida.com
61.142.208.162   80   sschuangshida.com"
源文件是没有空格的,我最终是想导出Execl. 
---------------------------
附操作XML的源码:XElement source = xDoc.Element("Sites");//MBProperty跟文档对象
            if (source.Elements("IIsWebServer").Count()>0)//IP地址和主机绑定在IIsWebServer节点的属性里面
            {
                foreach (XElement item in source.Elements("IIsWebServer"))
                {
                    site = new SiteServer();//创建实体类
                    site.Comment = item.Attribute("ServerComment").Value;//读取属性值                    site.Bindings = item.Attribute("ServerBindings")!= null ? item.Attribute("ServerBindings").Value : "没有主机头值";
                    siteList.Add(site);
                }
            }

解决方案 »

  1.   

    61.142.208.162:80:ss.sschuangshida.com61.142.208.162:80:www.sschuangshida.com61.142.208.162:80:sschuangshida.com可以用正则
    下午有时间帮你写
      

  2.   

     string str = "61.142.208.162:80:ss.sschuangshida.com61.142.208.162:80:www.sschuangshida.com61.142.208.162:80:sschuangshida.com";
            Regex re = new Regex(@"(?<title>(61\.142\.208\.162:80:ss\.sschuangshida\.com))");
            foreach (Match ma in re.Matches(str))
            {
                for(int i=0;i<ma.Groups["title"].Length;i++)
                {
                    Response.Write(ma.Groups[i] + "<br/>");
                }
            }
    //61.142.208.162:80:ss.sschuangshida.com
    //61.142.208.162:80:ss.sschuangshida.com
    //61.142.208.162:80:ss.sschuangshida.com
      

  3.   


     string tempStr ="61.142.208.162:80:ss.sschuangshida.com61.142.208.162:80:www.sschuangshida.com61.142.208.162:80:sschuangshida.com"
    ;            string pattern = @"([^:]+):([^:]+):([^\d]+)";
                string ss = Regex.Replace(tempStr,pattern,"$1 $2 $3 间隔符 ");间隔符 可以换成你想要的字符
      

  4.   

    晕··我就这样了。能实现效果了: private string GetStr(string str)
            {            
                StringBuilder strBud=new StringBuilder(str);
                strBud.Replace("61.","<br/>61.");//在IP的开头处添加一个标签,这个就没那么灵活            return strBud.ToString();
            }
      

  5.   

    不好怎么形容,能实现部分效果。
    我的需求是这样:每个域名都对应一个IP,即便IP相同都要对应,等于说100个站点信息,起码要显示100个IP。但你这个方法,值显示一个IP,接下来全是域名
      

  6.   


                string ServerBindings="61.142.208.162:80:ss.sschuangshida.com61.142.208.162:80:www.sschuangshida.com61.142.208.162:80:sschuangshida.com\"";
                string result = Regex.Replace(ServerBindings,@"(\d+\.){3}(\d+:){2}","<br/>$0");
                Console.WriteLine(result);
      

  7.   


       string str = "61.142.208.162:80:ss.sschuangshida.com61.142.208.162:80:www.sschuangshida.com61.142.208.162:80:sschuangshida.com";
            str = str.Replace("com","|");
         string [] arr = str.Split('|');        foreach (string s in arr)        {
                string[] arr1 = s.Split(':');
                for (int i = 0; i < arr1.Length;i++ )
                {
                   
                    if (i == (arr1.Length - 1))
                    {
                        Response.Write(arr1[i] + "com" + "<br>");                }                else
                    {
                        Response.Write(arr1[i] + "<br>");
                    
                    
                    }            }               
             }
      

  8.   

    你没考虑到还有这样的域名:www.xxsx.com.cn
      

  9.   

    c# 不熟,来段java的String str = "61.142.208.162:80:ss.sschuangshida.com61.142.208.162:80:www.sschuangshida.com61.142.208.162:80:sschuangshida.com";
    Pattern p = Pattern.compile("[A-Za-z][\\d]");
    StringBuilder sb = new StringBuilder(str.replace(":", " "));

    java.util.regex.Matcher m = p.matcher(sb);
    int i = 0;
    int curentIndex = 0;
    while(m.find()){
    curentIndex = m.start()+1;
    sb.insert(curentIndex+i, "|");
    i++;
    }
    String [] temps = sb.toString().split("\\|");

    System.out.println(Arrays.toString(temps));输出:
    [61.142.208.162 80 ss.sschuangshida.com, 61.142.208.162 80 www.sschuangshida.com6, 1.142.208.162 80 sschuangshida.com]
      

  10.   

    不好意思上面那段错了 String str = "611.142.208.162:80:ss.sschuangshida.com621.142.208.162:80:www.sschuangshida.com61.142.208.162:80:sschuangshida.com61.142.208.162:80:ss.sschuangshida.com61.142.208.162:80:www.sschuangshida.com61.142.208.162:80:sschuangshida.com";
    Pattern p = Pattern.compile("[A-Za-z][\\d]");
    StringBuilder sb = new StringBuilder(str.replace(":", " "));

    java.util.regex.Matcher m = p.matcher(sb);
    int curentIndex = 0;
    while(m.find()){
    curentIndex = m.start()+1;
    sb.insert(curentIndex, "|");
    }
    String [] temps = sb.toString().split("\\|");
    for(int i=0;i<temps.length;i++)
    System.out.println(temps[i]);输出:611.142.208.162 80 ss.sschuangshida.com
    621.142.208.162 80 www.sschuangshida.com
    61.142.208.162 80 sschuangshida.com
    61.142.208.162 80 ss.sschuangshida.com
    61.142.208.162 80 www.sschuangshida.com
    61.142.208.162 80 sschuangshida.com
      

  11.   


    public static void main(String[] args) {
    String str = "61.142.208.162:80:ss.sschuangshida.com61.142.208.162:80:ss.sschuangshida.com";
    str = str.replace(":", " ");


    Pattern p = Pattern.compile("[A-Za-z][\\d]"); //匹配字母紧挨着数字的地方  如m6 
    java.util.regex.Matcher m = p.matcher(str);

    StringBuilder temp = new StringBuilder();

    int curentIndex = 0;//用来标记下一个匹配的位置
    int tempIndex = 0;//用来标记上一个匹配的位置  截取字符串用到
    while(m.find()){
    curentIndex = m.start()+1;//当前匹配的位置
    temp.append(str.substring(tempIndex,curentIndex)).append("|");//截取上一个匹配的位置 到当前匹配的位置并且追加竖线用于标记
    tempIndex = curentIndex;//上一个匹配的位置
    }
    String [] temps = temp.toString().split("\\|");//用竖线分割数组
    if(temps.length==0){//在只有一个有规律的字符时会匹配不出来因为没有字母紧挨着数字的情况
    System.out.println(str);
    }
    for(int i=0;i<temps.length;i++)
    System.out.println(temps[i]);

    }