[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Convert 8 lines of Vb.net to c#

Posted on 2010-01-05
19
Medium Priority
?
216 Views
Last Modified: 2012-05-08
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
0
Comment
Question by:xterra
  • 5
  • 4
  • 2
  • +2
14 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 1000 total points
ID: 26187981
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
 
LVL 3

Expert Comment

by:roeib
ID: 26187999
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
 
LVL 4

Expert Comment

by:apexpert
ID: 26188009
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 4

Expert Comment

by:apexpert
ID: 26188012
use this link to further conversion---
http://www.developerfusion.com/tools/convert/vb-to-csharp/ 
0
 
LVL 13

Assisted Solution

by:zadeveloper
zadeveloper earned 1000 total points
ID: 26188079
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
 
LVL 13

Expert Comment

by:zadeveloper
ID: 26188083
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
 
LVL 1

Author Comment

by:xterra
ID: 26188103
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
 
LVL 1

Author Comment

by:xterra
ID: 26188108
zadeveloper, I didn't see yours yet. Allow me to try it, thanks.
0
 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 1000 total points
ID: 26188123
foreach (Match matchTitle in Regex.Matches(mGroup.ToString(), "\\b\\w[A-Z]{2,3}\\b"))
0
 
LVL 13

Assisted Solution

by:zadeveloper
zadeveloper earned 1000 total points
ID: 26188137
re:  26188103
compile error: mGroup.ToString needs a () at the end mGroup.ToString()
0
 
LVL 1

Author Comment

by:xterra
ID: 26188140
ZA, I'm also going to give you bonus for helping, if you can direct me on how to do so.
0
 
LVL 1

Author Comment

by:xterra
ID: 26188144
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
 
LVL 1

Author Comment

by:xterra
ID: 26196744
Hi South,
 Thanks for the response, I understand. Could you please give "za" 200 points if I have it?
0
 
LVL 13

Expert Comment

by:zadeveloper
ID: 26426635
I would say Points go to:

*Answers*
http:#a26187981
http:#a26188079

*Supporting the answers*
http:#a26188123
http:#a26188137
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Integration Management Part 2
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question