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);
}
}
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);
}
}
解决方案 »
- XML无法显示?????谁帮我搞定了马上结贴
- 不明白,求教:如何执行这种方法?难道是解决方案有问题?
- 拖asp.net ajax控件(或其它非自带控件,如水晶报表控件)到界面上,为什么总是弹出“对COM组件的调用返回了错误HRESULT E_FAIL。"的错误提
- 中国最牛.net开发平台特别开放24小时!
- FileUpload的onchange问题
- 妹妹告急 ~~~ TABLE如何删除列? 急
- 新人请教一个WEBAPI问题
- Spread中,如果控制滚动条的位置?敬请各位帮忙,小弟不胜感激!
- 高人啊~Server.HtmlEncode(xmlDescription) 后汉字还是汉字,这是怎么回事?
- 初学ASP请指教
- 为什么<在CS中运行时替换成了<而>没有替换
- 不知道下面代码中的Request["u"]是哪里来的
下午有时间帮你写
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
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 间隔符 ");间隔符 可以换成你想要的字符
{
StringBuilder strBud=new StringBuilder(str);
strBud.Replace("61.","<br/>61.");//在IP的开头处添加一个标签,这个就没那么灵活 return strBud.ToString();
}
我的需求是这样:每个域名都对应一个IP,即便IP相同都要对应,等于说100个站点信息,起码要显示100个IP。但你这个方法,值显示一个IP,接下来全是域名
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);
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>");
} }
}
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]
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
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]);
}