Reputation: 37
I know a string is just a set of characters. I have entered a string in to visual basic using a textbox.
message = textbox1.text
Can i now go and change the position of the characters in the string?
"Dogs" //string entered
"odsg" //that must be output in textbox2
textbox2.text = Encrypted
How do i do this?
Upvotes: 0
Views: 245
Reputation: 112259
I assume that you are trying to create a kind of autocorrect function like the one MS Word uses. I would use a dictionary to store corrections. The wrong word would be used as key and the right word as value
Dim dict = new Dictionary(Of String, String)
dict.Add("dogs", "odsg")
dict.Add("fiel", "file")
...
After having setup the dictionary
Dim input As String = textbox2.Text
Dim corrected As String
If dict.TryGetValue(LCase(input), corrected) Then
textbox2.Text = corrected
End If
Upvotes: 0
Reputation: 545488
Can i now go and change the position of the characters in the string?
No. Strings in .NET are immutable – they cannot be changed. In order to modify a string in VB, you call a function which creates a new string based off the modified contents of the old string. That’s what all the string methods are doing.
It’s not entirely clear what your encryption function is supposed to do though. It seems to permute the letter positions, but what schema does it use for that?
Upvotes: 4