I am required to write a program for visual basic 2008 in which I will process a delimited string which is formatted as such:
Word;Submitter;CorrectGuesses;IncorrectGuesses
I need to be able to edit the number of Correct or incorrect guesses when a matching value is found for both the word and the submitter. I believe that to do this I may need to use a combination of InStr and Mid functions, however I have very little knowledge of how these work.
If someone could help explain these functions specifically in this context, and/or possibly provide code that would achieve this, preferably well commented so I can see how the functions are working. To help me complete the final part of this project.
The split function is probably your best option:
Dim MyString As String = "Word;Submitter;CorrectGuesses;IncorrectGuesses"
Dim MyStringSplit() As String = MyString.Split(";")
Then after editing the strings you can join them back together like this:
Dim MYNewString As String = String.Join(";", MyStringSplit)
Added more code to tinstaafi's answer. However, I would like to highlight the fact that he has solved the crux of the problem.
Dim Correct as Integer
Dim InCorrect as Integer
Dim MyString As String = "Word;Submitter;CorrectGuesses;IncorrectGuesses"
Dim MyStringSplit() As String = MyString.Split(";")
Correct = MyStringSplit(2)
InCorrect = MyStringSplit(3)
' if answer is correct
Correct = Correct + 1
'if answer is incorrect
InCorrect = InCorrect + 1
MyStringSplit(2) = CStr(Correct)
MyStringSplit(3) = CStr(InCorrect)
Dim MYNewString As String = String.Join(";", MyStringSplit)
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.