[英]Convert code from c# to vb.net
I am using the below code in c# page. 我在c#页面中使用以下代码。 It's working fine.
一切正常。 I am new for vb.net.
我是vb.net的新手。 I convert the same using online converter but i got error i can't understood that error.
我使用在线转换器转换了相同的内容,但出现错误,我无法理解该错误。 Please help me to do the same.
请帮助我做同样的事情。
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
});
Error : 错误 :
Overload resolution failed because no accessible 'Replace' can be called with these arguments:
重载解析失败,因为无法使用以下参数调用可访问的“替换”:
'Public Function Replace(input As String, evaluator As System.Text.RegularExpressions.MatchEvaluator, count As Integer) As String': Value of type 'String' cannot be converted to 'System.Text.RegularExpressions.MatchEvaluator'.
'公共函数替换(输入为字符串,评估者为System.Text.RegularExpressions.MatchEvaluator,计数为整数)作为字符串':类型为'String'的值不能转换为'System.Text.RegularExpressions.MatchEvaluator'。
'Public Function Replace(input As String, evaluator As System.Text.RegularExpressions.MatchEvaluator, count As Integer) As String': Lambda expression cannot be converted to 'Integer' because 'Integer' is not a delegate type.......
“公共函数替换(输入为字符串,评估者为System.Text.RegularExpressions.MatchEvaluator,计数为整数)作为字符串”:Lambda表达式无法转换为“整数”,因为“整数”不是委托类型..... ..
Use below code 使用以下代码
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)
Or try this code 或尝试此代码
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"
}
)
You can use below code :- 您可以使用以下代码:-
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)
There you go, I converted it for you: 到这里,我为您转换了:
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.