-
Jan 3rd, 2016, 02:52 PM
#1
Thread Starter
New Member
Splitting String
I am experiencing a problem with splitting a two digit integer into two one digit integers (e.g. 17 = 1,7) the string.split variable doesn't seem to work as there is nothing between the two digits of the integer. Any help as to what I can use would be greatly appreciated, many thanks in advance.
Code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnInfo.Click
Dim SplitCV As Integer
Dim SplitCVSur As Integer
Dim NextIntCV(2) As Integer
Dim Output As Integer
Dim i As Integer
Dim NextStrCV() As String
Dim StrNCV As String
For Each C In txtFirst.Text
If C = "A" Or C = "J" Or C = "S" Then
SplitCV = SplitCV + 1
ElseIf C = "B" Or C = "K" Or C = "T" Then
SplitCV = SplitCV + 2
ElseIf C = "C" Or C = "L" Or C = "U" Then
SplitCV = SplitCV + 3
ElseIf C = "D" Or C = "M" Or C = "V" Then
SplitCV = SplitCV + 4
ElseIf C = "E" Or C = "N" Or C = "W" Then
SplitCV = SplitCV + 5
ElseIf C = "F" Or C = "O" Or C = "X" Then
SplitCV = SplitCV + 6
ElseIf C = "G" Or C = "P" Or C = "Y" Then
SplitCV = SplitCV + 7
ElseIf C = "H" Or C = "Q" Or C = "Z" Then
SplitCV = SplitCV + 8
ElseIf C = "I" Or C = "R" Then
SplitCV = SplitCV + 9
End If
Next C
For Each C In txtSur.Text
If C = "A" Or C = "J" Or C = "S" Then
SplitCVSur = SplitCVSur + 1
ElseIf C = "B" Or C = "K" Or C = "T" Then
SplitCVSur = SplitCVSur + 2
ElseIf C = "C" Or C = "L" Or C = "U" Then
SplitCVSur = SplitCVSur + 3
ElseIf C = "D" Or C = "M" Or C = "V" Then
SplitCVSur = SplitCVSur + 4
ElseIf C = "E" Or C = "N" Or C = "W" Then
SplitCVSur = SplitCVSur + 5
ElseIf C = "F" Or C = "O" Or C = "X" Then
SplitCVSur = SplitCVSur + 6
ElseIf C = "G" Or C = "P" Or C = "Y" Then
SplitCVSur = SplitCVSur + 7
ElseIf C = "H" Or C = "Q" Or C = "Z" Then
SplitCVSur = SplitCVSur + 8
ElseIf C = "I" Or C = "R" Then
SplitCVSur = SplitCVSur + 9
End If
Next C
lblName1.Text = SplitCV
lblName2.Text = SplitCVSur
If SplitCV = 0 Then
Console.WriteLine("Digit too small please try again")
End If
StrNCV = Str(SplitCV)
NextStrCV = Str(StrNCV).Split(" ")
For Each i In NextStrCV
Output = Output + i
Next i
lblInstructions.Text = Str(Output)
End Sub
End Class
-
Jan 3rd, 2016, 05:20 PM
#2
Re: Splitting String
Try using Substring method
Code:
StrNCV = SplitCV.ToString
For i = 0 To StrNCV.Length - 1
Output = Output + CInt(StrNCV.Substring(i, 1))
Next i
lblInstructions.Text = Output.ToString
-
Jan 3rd, 2016, 05:53 PM
#3
Re: Splitting String
Strings can be treated as arrays of Char, or you can use the Chars property to get the array.
For example:
Code:
Dim value As String = "17"
For i As Integer = 0 To value.Length - 1
Console.WriteLine(value(i))
Next
Dim digits() As Char = value.Chars
This answer is wrong. You should be using TableAdapter and Dictionaries instead.
-
Jan 3rd, 2016, 11:08 PM
#4
Re: Splitting String
I'd go straight for the Chars array...
-tg
-
Jan 4th, 2016, 02:08 PM
#5
Thread Starter
New Member
Re: Splitting String
Thanks all, you were all really helpful
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|