954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to extract substring from a string?

I have a string stored in a variable, say
myString= http://www.codeguru.com/icom_includes/feeds/codeguru/rss-all.xml
CodeGuru.comsomethinghttp://lifehacker.com/index.xml
Lifehackersomething
I want to extract the text between and
and also the text between and
in two different arrays.
How to do this, please help me. if anyone have code or any helpfull link please reply back.

Thanks

ansari.wajid
Light Poster
47 posts since Aug 2007
Reputation Points: 10
Solved Threads: 0
 

hi

Now Remember that i can only show you the door , you are the only person who have to walk throught it. i have created a substring and displayed them on the Messagebox, you have to assign that to the Array. here is the example code

String myString = @"<RssFeeds<link>http://www.codeguru.com/icom_includes/feeds/codeguru/rss-all.xml</link>
    <title>CodeGuru.com</title>   <description>something</description></RssFeeds><RssFeeds><link>http://lifehacker.com/index.xml</link>
    <title>Lifehacker</title>
    <description>something</description>
  </RssFeeds> ";
   MessageBox.Show(myString.Substring(15, 64)); /*It gave me  <a href="http://www.codeguru.com/icom_includes/feeds/codeguru/rss-all.xml">http://www.codeguru.com/icom_includes/feeds/codeguru/rss-all.xml</a>  */
   MessageBox.Show(myString.Substring(99,12)); //CodeGuru.com


Hope this Helps

vuyiswamb
Posting Whiz
312 posts since Mar 2007
Reputation Points: 31
Solved Threads: 14
 

Use a System.Text.RegularExpressions.Regex object.

Regex linkRegex = new Regex(@"<link>\s*(?<link>[^<]+)\s*</link>", System.Text.RegularExpressions.RegexOptions.Compiled);
            Regex titleRegex = new Regex(@"<title>\s*(?<title>[^<]+)\s*</title>", System.Text.RegularExpressions.RegexOptions.Compiled);

            if ( linkRegex.IsMatch(myString) ) {
                Match match = linkRegex.Match(myString);
                string theLink = match.Groups["link"].Value;
            }
            if ( titleRegex.IsMatch(myString) ) {
                Match match = titleRegex.Match(myString);
                string title = match.Groups["link"].Value;
            }
nvmobius
Light Poster
39 posts since Jul 2008
Reputation Points: 11
Solved Threads: 4
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You