什么是C#等效项:
Public stringValue As String
Public intValue As Integer
intValue = Format(val(stringValue), "00")
?
因此vb6 Format
函数将转换为字符串,而Val
函数将转换为数字。如果您查看Microsoft documentation for Val:
Val(" 1615 198th Street N.E.")
// returns
1615198
在c#中,可以很笨拙地转换为
string stringValue = " 1615 198th Street N.E.";
// assign to int if int wanted
// throws exception if cannot be converted to int, use Int32.TryParse if you want to handle that
int intValue = System.Convert.ToInt32(
new string(stringValue.Replace(" ", "").TakeWhile(System.Char.IsDigit).ToArray())
);
System.Console.WriteLine(intValue);
这实际上取决于您对stringValue
将会是什么以及您想要返回什么的期望。另外,我不认为您可以为string
分配int
值,所以像在vb6中那样随意。它肯定可以清除,但这仅取决于您在做什么。