Parsing A String

sohoportal

New member
Joined
Jul 19, 2005
Messages
3
Location
Ottawa, Canada
Programming Experience
Beginner
Hello,


I'm new to VB.NET and on a steep learning curve. I've created a char array and I'm trying to figure out how to disassemble the string, convert the individual chracters to ASCII, then re-arrange the string.

Here's what I have so far. Any help would be appreciated.

Private Sub btnEncrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEncrypt.Click

Dim aChar As Char()

aChar = txtbxUserString.Text.ToCharArray

Dim i As Int16

For i = 0 To aChar.GetUpperBound(0)

txtbxUserString.Text = (AscW(aChar(i)))

Next

End Sub

 
Are you trying to display the string with each character replaced by its Unicode code? If so, you are on the right track. In your loop, you are setting the Text of the TextBox to each individual character each time, rather than adding the character. I suggest you use a String variable that you initialise to an empty string, then use "&=" to concatenate each code in the loop. Then you can assign the full string to the TextBox at the end. The reason for using the intermediate variable is that it is not recommended that you do multiple operations on a visible element in quick succession as it can look bad to the user. Better to do all the calculations in the background and then make a single visible change.
 
Hi jmcilhinney,

Thank you for your response.

Yes, I am trying to replace the original string character with its unicode equivalent and concatenate the end result to display. I understand what you mean to intialize the string to "". Would you mind giving me an example of what you mean to use "&=" to concatenate each code in the loop.

Here's the full jist of what I'm trying to accomplish. I want to take the first character of a string and change it to it unicode equivalent, I then want to do the same thing with a second string. Once I've done this I want to add each the first elements from the two strings together (now in unicode), then continue to do the same until I've exhausted the full character set for the first string. Once I've done this I will reverse the process; an encrypt/decrypt exercise.

Thank you for your help, it is greatly appeciated.

Garry
 
Last edited:
VB.NET:
string1 &= string2
is equvalent to
VB.NET:
string1 = string1 & string2
which concatenates string1 and string2 and assigns the result to string1. There are corresponding +=, -=, *= and /= operators for adding to a variable, subtracting, multiplying and dividing.
 
Back
Top