简体   繁体   中英

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. But i am not able to convert some code in vb.net.

C# Code:

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

Vb.net Code:

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. But in Vb.net i can't get the numeric value of a to compare with the ASCII value. If there is any possible to convert the c# project solution into vb.net solution? 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

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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