拆分字符串并获取数据 [英] split string and get data

查看:59
本文介绍了拆分字符串并获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <   span     class   =  jcn >  



< a < span class =code-attribute> href = title =' ' > 转到.. < / a >
< a href = title < span class =code-keyword> =' ' > 转到.. < / a >



< a < span class =code-attribute> href = http://www.mysite.com title =' < span class =code-keyword>阿尔卡普里的Asha Computers,VADODARA' > Asha Computers < / a >
< / span >



i现在有字符串中的数据,我想从中搜索数据。

例如:http://www.mysite.com



我该怎么办?



谢谢你,

解决方案

使用正则表达式:

(?< = href = [\'])([^ \'] +)

应该这样做


你也可以试试下面的代码。



 string htmlString =< a href =\http://www.mysite.com \ title =Asha Computers in Alkapuri,VADODARA> Asha Computers< / a>; 
string serachFor =< a href =\http;< brmode =hold/> int startIndx = htmlString.IndexOf(serachFor);
int endIndx = htmlString .IndexOf('',startIndx + serachFor.Length);
string href =http:+ htmlString.Substring(startIndx + serachFor.Length,endIndx - (startIndx + serachFor.Length));


这将对您有所帮助

<span class="jcn">
.
.
.
<a href="#" title=''>Go to..</a>
<a href="#" title=''>Go to..</a>
.
.
.
                <a href="http://www.mysite.com" title='Asha Computers in Alkapuri, VADODARA' >Asha Computers</a>
            </span>


i have data like above in string now i want to search out data from this.
like e.g: "http://www.mysite.com"

for that what should i do ?

thank you,

解决方案

Use a regex:

(?<=href=[\'"])([^\'" ]+)

Should do it


You can also try below code.

string htmlString = "<a href="\"http://www.mysite.com\"" title="Asha Computers in Alkapuri, VADODARA">Asha Computers</a>";
   string serachFor = "<a href="\"http";<br" mode="hold" />            int startIndx = htmlString.IndexOf(serachFor);
   int endIndx = htmlString.IndexOf('"',startIndx + serachFor.Length);
   string href ="http:" + htmlString.Substring(startIndx + serachFor.Length, endIndx - (startIndx + serachFor.Length));


This will help you


这篇关于拆分字符串并获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆