| | |
how to extract substring from a string?
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2007
Posts: 33
Reputation:
Solved Threads: 0
I have a string stored in a variable, say
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>
I want to extract the text between <link>and </link>
and also the text between <title>and </title>
in two different arrays.
How to do this, please help me. if anyone have code or any helpfull link please reply back.
Thanks
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>
I want to extract the text between <link>and </link>
and also the text between <title>and </title>
in two different arrays.
How to do this, please help me. if anyone have code or any helpfull link please reply back.
Thanks
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
Hope this Helps
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
C# Syntax (Toggle Plain Text)
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 rel="nofollow" class="t" href="http://www.codeguru.com/icom_includes/feeds/codeguru/rss-all.xml" target="_blank">http://www.codeguru.com/icom_include...ru/rss-all.xml</a> */ MessageBox.Show(myString.Substring(99,12)); //CodeGuru.com
Hope this Helps
Last edited by Tekmaven; Aug 8th, 2008 at 4:44 pm. Reason: Code tags
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
•
•
Join Date: Jul 2008
Posts: 39
Reputation:
Solved Threads: 4
Use a System.Text.RegularExpressions.Regex object.
C# Syntax (Toggle Plain Text)
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; }
![]() |
Similar Threads
- How to extract a substring from a char* (C++)
- Finding the first number char in a string (Java)
- Creating the piglatin version of a string (Java)
Other Threads in the C# Forum
- Previous Thread: import image to db
- Next Thread: schedulinga task
| Thread Tools | Search this Thread |
.net access algorithm array barchart bitmap box broadcast c# check checkbox client combobox control conversion csharp custom cyclethruopenforms data database datagrid datagridview dataset date/time datetime degrees development dll draganddrop drawing encryption enum event excel file finalyearproject form format forms function gdi+ getoutlookcontactusinfcsvfile globalization httpwebrequest image index input install installer java label list listbox mandelbrot math mono mouseclick mysql operator panel path photoshop picturebox pixelinversion post programming radians regex remote remoting richtextbox save server silverlight sleep socket sql sql-server statistics stream string table text textbox thread time timer timespan update usercontrol users validate validation visualstudio webbrowser wia windows winforms wpf xml





