将代码从c#转换为vb.net

时间:2014-08-07 04:53:17

标签: c# vb.net converter

我在c#页面中使用以下代码。它工作正常。我是vb.net的新手。我使用在线转换器转换相同但我得到错误我无法理解该错误。请帮我做同样的事。

string StrInputParam = "TYPE:5#MOBILE:" + Mobile + "#PASS:" + Password + "";
string StrSPName = ConfigurationManager.AppSettings["SP_RED_USER_DETAILS"];
string[] ArrayVal = StrInputParam.Split('#');

StrSPName = Regex.Replace(StrSPName, @"\[(.+?)\]", m =>
{
    string StrParamName = m.Groups[1].Value;
    string StrParamValue = ArrayVal.Select(s => s.Split(new[] { ':' }, 2))
                                .Where(p => p.Length == 2)
                                .Where(p => p[0] == StrParamName)
                                .Select(p => p[1])
                                .FirstOrDefault();
    return StrParamValue ?? "0"; // "0" instead of m.Value
});

错误

  

重载解析失败,因为无法使用以下参数调用可访问的“替换”:

     

'公共函数替换(输入为字符串,求值程序为System.Text.RegularExpressions.MatchEvaluator,count as Integer)As String':类型'String'的值不能转换为'System.Text.RegularExpressions.MatchEvaluator'。

     

'公共函数替换(输入为字符串,求值程序为System.Text.RegularExpressions.MatchEvaluator,count as Integer)As String':Lambda表达式无法转换为“Integer”,因为“Integer”不是委托类型。 .....

3 个答案:

答案 0 :(得分:1)

使用以下代码

Dim StrInputParam As String = "TYPE:5#MOBILE:" + Mobile + "#PASS:" + Password + ""
Dim StrSPName As String = ConfigurationManager.AppSettings("SP_RED_USER_DETAILS")
Dim ArrayVal As String() = StrInputParam.Split("#"C)

StrSPName = Regex.Replace(StrSPName, "\[(.+?)\]", Function(m) 
 Dim StrParamName As String = m.Groups(1).Value
 Dim StrParamValue As String = ArrayVal.Select(Function(s) s.Split(New () {":"C}, 2))
                                       .Where(Function(p) p.Length = 2)
                                       .Where(Function(p) p(0) = StrParamName)
                                       .Select(Function(p) (1))
                                       .FirstOrDefault()
 Return If(StrParamValue, "0")   
End Function)

或尝试此代码

Dim StrInputParam As String =  "TYPE:5#MOBILE:" + Mobile + "#PASS:" + Password + "" 
Dim StrSPName As String =  ConfigurationManager.AppSettings("SP_RED_USER_DETAILS") 
Dim ArrayVal() As String =  StrInputParam.Split("#"c) 

StrSPName = Regex.Replace(StrSPName, "\[(.+?)\]", m =>
{
    Dim StrParamName As String =  m.Groups(1).Value 
    Dim StrParamValue As String =  ArrayVal.Select(s  = > s.Split(New()
    {
         ":"c 
    }
, 2))
                                .Where(p => p.Length = 2)
                                .Where(p => p(0) = StrParamName)
                                .Select(p => p(1))
                                .FirstOrDefault()
    Return StrParamValue ?? "0"
}
)

答案 1 :(得分:1)

您可以使用以下代码: -

Dim StrInputParam As String = "TYPE:5#MOBILE:" & Mobile & "#PASS:" & Password & ""
Dim StrSPName As String = ConfigurationManager.AppSettings("SP_RED_USER_DETAILS")
Dim ArrayVal As String() = StrInputParam.Split("#"C)

StrSPName = Regex.Replace(StrSPName, "\[(.+?)\]", Function(m) 
Dim StrParamName As String = m.Groups(1).Value
Dim StrParamValue As String = ArrayVal.[Select](Function(s) s.Split(New () {":"C}, 2)).Where(Function(p) p.Length = 2).Where(Function(p) p(0) = StrParamName).[Select](Function(p) p(1)).FirstOrDefault()
    ' "0" instead of m.Value
Return If(StrParamValue, "0")

End Function)

答案 2 :(得分:0)

你去了,我为你转换了它:

Dim StrInputParam As String = "TYPE:5#MOBILE:" & Mobile & "#PASS:" & Password & ""
Dim StrSPName As String = ConfigurationManager.AppSettings("SP_RED_USER_DETAILS")
Dim ArrayVal() As String = StrInputParam.Split("#"c)

StrSPName = Regex.Replace(StrSPName, "\[(.+?)\]", Function(m) ' "0" instead of m.Value
      Dim StrParamName As String = m.Groups(1).Value
      Dim StrParamValue As String = ArrayVal.Select(Function(s) s.Split( { ":"c }, 2)).Where(Function(p) p.Length = 2).Where(Function(p) p(0) = StrParamName).Select(Function(p) p(1)).FirstOrDefault()
      Return If(StrParamValue, "0")
End Function)