将代码从c#转换为vb.net
本文关键字:vb net 转换 代码 | 更新日期: 2023-09-27 18:16:48
我在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
});
误差:
重载解析失败,因为没有可访问的'Replace'可以用这些参数调用:
` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` `MatchEvaluator, count As Integer) As String': 'String'类型的值不能转换为' system . text . regulareexpressions .MatchEvaluator'.
` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` `MatchEvaluator, count As Integer) As String': Lambda表达式不能转换为'Integer',因为'Integer'不是委托类型.......
可以使用下面的代码:-
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)
使用下面的代码
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"
}
)
好了,我帮你转换了:
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)