Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
166 views
in Technique[技术] by (71.8m points)

vb.net - simple VB code help

I am a java devloper and I wish to convert following code to java can any VB devloper tell me what following does?

    temp8Bit = 0
    temp8Bit = Convert.ToByte(tempRMACode.ToCharArray().GetValue(0))
             + Convert.ToByte((tempRMACode.ToCharArray()).GetValue(7))
    rmaValidationCode += String.Format("{0:X2}", temp8Bit)

tempRMACode is a string

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

What it's going to do is take the 0th & 7th character from the tempRMACode string, convert those values to Bytes and then add them. Convert is applied to the ASCII value of the character. So Convert.ToByte("A") == 65 the ASCII value of A.

String.Format("{0:X2}", temp8bit) is going to take the numeric value of temp8bit and give you the HEX value. So if you had the number 121 in temp8bit, you'd get 79 in rmaValidationCode.


Given the following:

Dim temp8bit As Byte
Dim tempRMACode As String = "A234567890"

Dim rmaValidationCode As String = String.Empty

temp8Bit = 0
temp8bit = Convert.ToByte(tempRMACode.ToCharArray().GetValue(0)) _
     + Convert.ToByte((tempRMACode.ToCharArray()).GetValue(7))

Dim a As String = tempRMACode.ToCharArray().GetValue(0)
Dim b As String = tempRMACode.ToCharArray().GetValue(7)

Dim c As Byte = Convert.ToByte(tempRMACode.ToCharArray().GetValue(0))
Dim d As Byte = Convert.ToByte(tempRMACode.ToCharArray().GetValue(7))

rmaValidationCode += String.Format("{0:X2}", temp8bit)

the output is:

temp8bit = 121 or 0x79
a = "A"
b = "8"
c = 65
d = 56
rmaValidationCode = "79"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...