I currently receive the input of the String from various input boxes in visual Basic. This is the added to a string to make a bigger string. The string looks like this (don't worry about the variable names):
Dim String1 As String = "12345"
What I do after this is create a string with spaces between every digit. This means the String gets converted to this (using a for loop):
Dim newString As String = "1 2 3 4 5"
For this I split the string into an Array using the split function whenever it comes across a String. This create a new array called result() (As a String).
When trying to read the individual items in the array, it works, and I get the correct results returned. Here is where the fun starts. when accessing the items individually and converting them to integers using the "Convert.ToInt32" function works like a charm. It allows me to do what I want to do. But, accessing every item in the array like this is not an option, as it will get out of control very quickly. so what I'm trying to do is create a new for loop to go through the array, and convert every item to a integer as well as adding them together while converting them. This is where the issue comes in.
Dim calcu As Integer = 0
For i As Integer = 0 To result.Length - 1
calcu += Convert.ToInt32(result(i))
Next i
the code above is the code I currently use to add the new value to the array. This however crashes and gives me the following error: "Input string was not in the correct format". what method can I use to convert this string to an integer?
what I'm trying to achieve is adding every value in the string together to give me a value in and integer.
newString.Split(' ').Sum(Function(s) Integer.Parse(s))