Click here to Skip to main content
15,891,981 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
XML
<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,
Posted
Updated 17-Jun-13 2:05am
v5

Use a regex:
(?<=href=[\'"])([^\'" ]+)
Should do it
 
Share this answer
 
Comments
johannesnestler 17-Jun-13 8:57am    
Yes, I'd recomend regex too for this kind of job.
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));
 
Share this answer
 
Comments
johannesnestler 17-Jun-13 8:56am    
maybe a solution, but way to inefficient...
 
Share this answer
 
Hi,

if you dont dont want to use regex, you can use the the string-methods to seperate your string and save the seperated parts in a list. when you have your seperated strings in your list, you can easily run any kind of operation on them.

C#
string str = "this is an example + which i want to seprate by plus";
string[] splittedString = str.Split('+');

foreach(string s in splittedString)
{
   //do something with it
}


maybe this will help.
 
Share this answer
 
C#
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.mysite.com");
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();

        if (response.StatusCode == HttpStatusCode.OK)
        {
            Stream receiveStream = response.GetResponseStream();
            StreamReader readStream = null;

            if (response.CharacterSet == null)
                readStream = new StreamReader(receiveStream);
            else
                readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet));
         


           string data1 = readStream.ReadToEnd();
}          
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900