locked
Problem with c# function RRS feed

  • Question

  • User2074080259 posted

    public static string UpperFirst(string s)<o:p></o:p>

    {<o:p></o:p>

    return Regex.Replace(s, @"%[a‐z]",<o:p></o:p>

    delegate(Match match){<o:p></o:p>

    string v = match.ToString();<o:p></o:p>

    return "%" + char.ToUpper(v[1]);<o:p></o:p>

    }<o:p></o:p>

    );<o:p></o:p>

    }


    Hello, can anyone help me translate this code to vb.net?

    Tuesday, March 16, 2010 12:35 PM

Answers

  • User551462331 posted

    i would write that code in vb as..

        Public Shared Function UpperFirst(ByVal s As String) As String
            Dim myEvaluator As New MatchEvaluator(AddressOf RegexEvaluator)
            Regex.Replace(s, "%[a‐z]", myEvaluator)
        End Function
    
        Public Function RegexEvaluator(ByVal str As Match) As String
            Dim v As String = str.ToString()
            Return "%" + Char.ToUpper(v(1))
       End Function


     

    for broadly converting c# to vb or vice versa, u can use this online tool

    http://www.developerfusion.com/tools/convert/csharp-to-vb/

    this is not able to convert delegate part though..... (everything is not perfect)

    so, i modified that part..

    hope this helps...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 16, 2010 3:45 PM
  • User397347636 posted

    (via Instant VB)

    VB9:

    Public Shared Function UpperFirst(ByVal s As String) As String
    	Return Regex.Replace(s, "%[a‐z]", Function(match) AnonymousMethod1(match))
    End Function
    
    Private Shared Function AnonymousMethod1(ByVal match As Match) As String
    	Dim v As String = match.ToString()
    	Return "%" & Char.ToUpper(v.Chars(1))
    End Function


    VB10: 

    Public Shared Function UpperFirst(ByVal s As String) As String
    	Return Regex.Replace(s, "%[a‐z]", Function(match As Match)
    		Dim v As String = match.ToString()
    		Return "%" & Char.ToUpper(v.Chars(1))
    	End Function)
    End Function


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 16, 2010 7:58 PM

All replies

  • User551462331 posted

    i would write that code in vb as..

        Public Shared Function UpperFirst(ByVal s As String) As String
            Dim myEvaluator As New MatchEvaluator(AddressOf RegexEvaluator)
            Regex.Replace(s, "%[a‐z]", myEvaluator)
        End Function
    
        Public Function RegexEvaluator(ByVal str As Match) As String
            Dim v As String = str.ToString()
            Return "%" + Char.ToUpper(v(1))
       End Function


     

    for broadly converting c# to vb or vice versa, u can use this online tool

    http://www.developerfusion.com/tools/convert/csharp-to-vb/

    this is not able to convert delegate part though..... (everything is not perfect)

    so, i modified that part..

    hope this helps...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 16, 2010 3:45 PM
  • User397347636 posted

    (via Instant VB)

    VB9:

    Public Shared Function UpperFirst(ByVal s As String) As String
    	Return Regex.Replace(s, "%[a‐z]", Function(match) AnonymousMethod1(match))
    End Function
    
    Private Shared Function AnonymousMethod1(ByVal match As Match) As String
    	Dim v As String = match.ToString()
    	Return "%" & Char.ToUpper(v.Chars(1))
    End Function


    VB10: 

    Public Shared Function UpperFirst(ByVal s As String) As String
    	Return Regex.Replace(s, "%[a‐z]", Function(match As Match)
    		Dim v As String = match.ToString()
    		Return "%" & Char.ToUpper(v.Chars(1))
    	End Function)
    End Function


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 16, 2010 7:58 PM