| | |
Need help with Array
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
By using Regex I've got links from an HTML Source.
But now I want to save these links into a new array so that I can later use them. I mean, I want all the "m.Groups[]" in a new array.
Here's my code:
Thanks in advance.
But now I want to save these links into a new array so that I can later use them. I mean, I want all the "m.Groups[]" in a new array.
Here's my code:
C# Syntax (Toggle Plain Text)
String html = getSource(); r = new Regex("class=lnk href\\s*=\\s*(?:\"(?<1>[^\"]*)\"|(?<1>\\S+))", RegexOptions.IgnoreCase | RegexOptions.Compiled); for (m = r.Match(html); m.Success; m = m.NextMatch()) { MessageBox.Show("Link" + m.Groups[1].Value); }
Thanks in advance.
Last edited by farooqaaa; Jul 18th, 2009 at 3:51 pm.
C# Syntax (Toggle Plain Text)
String html = getSource(); List<Group> newGroups = new List<Group>(); r = new Regex("class=lnk href\\s*=\\s*(?:\"(?<1>[^\"]*)\"|(?<1>\\S+))", RegexOptions.IgnoreCase | RegexOptions.Compiled); for (m = r.Match(html); m.Success; m = m.NextMatch()) { MessageBox.Show("Link" + m.Groups[1].Value); //new modified code newGroups.Add(m.Groups[index]); //not 1 as you say }
Read my comments in the code I may got you wrong.
Last edited by Ramy Mahrous; Jul 18th, 2009 at 4:49 pm.
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Thanks.
The "index" doesn't work. It say "index" doesn't exist.
I've modified the code, read the comments:
I hope you'll get me now.
Thanks again for your help.
The "index" doesn't work. It say "index" doesn't exist.
I've modified the code, read the comments:
C# Syntax (Toggle Plain Text)
String html = getSource(); // I want a list of "Strings" List<String> links = new List<String>(); r = new Regex("class=lnk href\\s*=\\s*(?:\"(?<1>[^\"]*)\"|(?<1>\\S+))", RegexOptions.IgnoreCase | RegexOptions.Compiled); for (m = r.Match(html); m.Success; m = m.NextMatch()) { //MessageBox.Show("Link" + m.Groups[1].Value); links.Add(m.Groups[1].Value); } // This messagebox only show 1 link while the above messagebox showed all the links (that matched the regex). for (int i = 0; i < links.Count; i++) { MessageBox.Show(links[i]); }
I hope you'll get me now.
Thanks again for your help.
Last edited by farooqaaa; Jul 18th, 2009 at 5:10 pm.
Sure it won't work as index not defined but what I need to say is you everytime add the same Group instance which in the index 1 of the array of Group.
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Hmm. But that's what MSDN gave me.
Anyways, I did this in VB and its working properly. Here's the code:
Can you look at that code and get ideas and then get me the C# code, please? Will be really appreciated.
Thanks!
Anyways, I did this in VB and its working properly. Here's the code:
Can you look at that code and get ideas and then get me the C# code, please? Will be really appreciated.
C# Syntax (Toggle Plain Text)
Dim r As New Regex("class=lnk href\s*=\s*(?:""(?<1>[^""]*)""|(?<1>\S+))", RegexOptions.IgnoreCase Or RegexOptions.Compiled) Dim m As Match Dim matches As New List(Of String) // this is the new array // The code below code works fine For Each m In r.Matches(HTML CODE) matches.Add(m.Groups(1).Value) Next
Thanks!
Last edited by farooqaaa; Jul 18th, 2009 at 5:42 pm.
Can you please give me the link? to know what's this about.
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
The regex scans for "<a href=link.com>Link</a>" and gets the link.
Here's link to MSDN, I am using this code:
http://msdn.microsoft.com/en-us/libr...fx(VS.71).aspx
The code they gave me works very great for me. But I don't know how to save the matches in a new array. That's all I want to do.....Save the matches in a new array.
Here's link to MSDN, I am using this code:
http://msdn.microsoft.com/en-us/libr...fx(VS.71).aspx
The code they gave me works very great for me. But I don't know how to save the matches in a new array. That's all I want to do.....Save the matches in a new array.
Last edited by farooqaaa; Jul 18th, 2009 at 5:53 pm.
C# Syntax (Toggle Plain Text)
String html = richTextBox1.Text; List<string> matches = new List<string>(); Regex r = new Regex("href\\s*=\\s*(?:\"(?<1>[^\"]*)\"|(?<1>\\S+))", RegexOptions.IgnoreCase | RegexOptions.Compiled); Match m;// = r.Match( for (m = r.Match(html); m.Success; m = m.NextMatch()) { matches.Add(m.Value); MessageBox.Show(m.Value); //new modified code //newGroups.Add(m.Groups[index]); //not 1 as you say }
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
That's what you needed?? or it popup unneeded string?
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
![]() |
Similar Threads
- Can I ghost a RAID array??? (Windows NT / 2000 / XP)
- Creating dynamic array structures (C++)
- Array limit (C)
- struct dynamic 2d array alloc (C)
- string to integer array transformation (C)
- Array (Visual Basic 4 / 5 / 6)
Other Threads in the C# Forum
- Previous Thread: self-aware strings
- Next Thread: Replace the Contents of the Array
| Thread Tools | Search this Thread |
.net 2007 access ado.net algorithm array barchart bitmap box broadcast buttons c# check checkbox client color combobox control conversion csharp custom database databaseconnection datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file files form format formbox forms function gdi+ httpwebrequest image index input install java label list listbox listener mandelbrot math mouseclick msword mysql opening operator parse path photoshop picturebox pixelinversion post programming radians regex remote remoting richtextbox save saving serialization server sleep socket sql statistics stream string table tcp temperature text textbox thread time timer update usercontrol validation view visualstudio webbrowser windows winforms wpf xml






. That code worked!