Convert 8 lines of Vb.net to c#

500 points. Thanks.

 Dim RegexExpression As String = "title=""(.*?)"""
        Dim stingtobematched As String = line
        For Each mGroup As Group In Regex.Match(stingtobematched, RegexExpression).Groups
            If TypeOf mGroup Is Match Then
            Else
                For Each matchTitle As Match In Regex.Matches(mGroup.ToString, "\b\w[A-Z]{2,3}\b")
                    lstSymbols.Items.Add(matchTitle.Value)
                Next
            End If

        Next
LVL 1
xterraAsked:
Who is Participating?
 
DhaestCommented:
A good starting point for conversion of code (not always completely correct)

http://www.developerfusion.com/tools/convert/vb-to-csharp/
using System.Text.RegularExpressions;


            string RegexExpression = "title=\"(.*?)\"";
            string stingtobematched = line;
            foreach (Group mGroup in Regex.Match(stingtobematched, RegexExpression).Groups)
            {
                if (mGroup is Match)
                {
                }
                else
                {
                    foreach (Match matchTitle in Regex.Matches(mGroup.ToString, "\\b\\w[A-Z]{2,3}\\b"))
                    {
                        lstSymbols.Items.Add(matchTitle.Value);
                    }

                }
            } 

Open in new window

0
 
roeibCommented:
string RegexExpression = "title=""(.*?)""";
string stingtobematched = line;

foreach (Group mGroup in Regex.Match(stingtobematched, RegexExpression).Groups)
{
      if(mGroup is Match)
      {}
      else
      {      
                foreach (Match matchTitle in Regex.Matches(mGroup.ToString, "\b\w[A-Z]{2,3}\b"))
                {
             lstSymbols.Items.Add(matchTitle.Value);
                              }
      }
}

enjoy
0
 
apexpertCommented:
string RegexExpression = "title=\"(.*?)\"";
    string stingtobematched = line;
    foreach (Group mGroup in Regex.Match(stingtobematched, RegexExpression).Groups) {
        if (mGroup is Match) {
        }
        else {
            foreach (Match matchTitle in Regex.Matches(mGroup.ToString, "\\b\\w[A-Z]{2,3}\\b")) {
                lstSymbols.Items.Add(matchTitle.Value);
            }
        }
    }
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
apexpertCommented:
use this link to further conversion---
http://www.developerfusion.com/tools/convert/vb-to-csharp/ 
0
 
zadeveloperCommented:
The Direct Translation (in best practice) / fewest lines of c# code
foreach (var mGroup in Regex.Match(line, "title=\"\"(.*?)").Groups)
            {
                if ((mGroup is Match)) continue;

                foreach (Match matchTitle in Regex.Matches(mGroup.ToString(), @"\b\w[A-Z]{2,3}\b"))
                    lstSymbols.Items.Add(matchTitle.Value);
                
            }

Open in new window

0
 
zadeveloperCommented:
This is an Ideal example of when you should be using LINQ.
So check this out as well.

foreach (var matchValue in from object mGroup in Regex.Match(line, "title=\"\"(.*?)").Groups
                                         where (!(mGroup is Match))
                                         from Match matchTitle in Regex.Matches(mGroup.ToString(), @"\b\w[A-Z]{2,3}\b")
                                         select matchTitle.Value)
            {
                lstSymbols.Items.Add(matchValue);
            }

Open in new window

0
 
xterraAuthor Commented:
Hi guys,
 All three work *almost*, but I get a compile error on this line:

 foreach (Match matchTitle in Regex.Matches(mGroup.ToString, "\\b\\w[A-Z]{2,3}\\b"))


Error:
       The best overloaded method match for 'System.Text.RegularExpressions.Regex.Matches(string, string)' has some invalid arguments       
0
 
xterraAuthor Commented:
zadeveloper, I didn't see yours yet. Allow me to try it, thanks.
0
 
DhaestCommented:
foreach (Match matchTitle in Regex.Matches(mGroup.ToString(), "\\b\\w[A-Z]{2,3}\\b"))
0
 
zadeveloperCommented:
re:  26188103
compile error: mGroup.ToString needs a () at the end mGroup.ToString()
0
 
xterraAuthor Commented:
ZA, I'm also going to give you bonus for helping, if you can direct me on how to do so.
0
 
xterraAuthor Commented:
THe reason I accepted the other is because for some reason, his regex worked. But since you were close, I can give you the same amount because I am pretty sure I have akot of unused.
0
 
xterraAuthor Commented:
Hi South,
 Thanks for the response, I understand. Could you please give "za" 200 points if I have it?
0
 
zadeveloperCommented:
I would say Points go to:

*Answers*
http:#a26187981
http:#a26188079

*Supporting the answers*
http:#a26188123
http:#a26188137
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.