简体   繁体   English

如何将C#代码转换为vb.net。 获取字符的数值时发生错误

[英]How to convert c# code to vb.net. Error occurred in getting numeric value of a character

I am trying to convert the c# project into vb.net project. 我正在尝试将c#项目转换为vb.net项目。 But i am not able to convert some code in vb.net. 但是我无法在vb.net中转换一些代码。

C# Code: C#代码:

if ((a >= 33) && (a <= 48)) { word += "|"; word1 += "|"; }

Vb.net Code: Vb.net代码:

If (Char.GetNumericValue(a) >= 33) AndAlso (Char.GetNumericValue(a) <= 48) Then
    word += "|"
    word1 += "|"
End If

Here in c# the numeric value of a is directly compared with integer value. 在c#中,将a的数值直接与整数值进行比较。 But in Vb.net i can't get the numeric value of a to compare with the ASCII value. 但是在Vb.net中,我无法获取a的数值与ASCII值进行比较。 If there is any possible to convert the c# project solution into vb.net solution? 是否有可能将c#项目解决方案转换为vb.net解决方案? Let me know the solution. 让我知道解决方案。 Thanks in advance. 提前致谢。

you can convert a character value into its ASC value and then compare it with a value in vb.net find sample code as below 您可以将字符值转换为其ASC值,然后将其与vb.net中的值进行比较,找到以下示例代码

Dim a As Char
a = "a"
Dim i As Integer = Asc(a)
Console.Write(i.ToString())
If i < 90 Then
    'Do what you want
End If

You should be using the VB 'AscW' function (not 'Asc'), assuming that 'a' is a char: 您应该使用VB的“ AscW”功能(而不是“ Asc”),并假设“ a”是一个字符:

If (AscW(a) >= 33) AndAlso (AscW(a) <= 48) Then
    word &= "|"
    word1 &= "|"
End If

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM