• Status: Solved
• Priority: Medium
• Security: Public
• Views: 142

# formatting strings

If I have a string like 1,2,3,4,5,6,... how do I convert this into separate integers like 1 2 3 4 5 6 ....  So the question is how do I remove the commas and convert this string into the integers that are separated by the commas.
0
• 3
1 Solution

Commented:
You have to build your own function that will handel this for you. Use the instr function to help you search for commas, or maybe use the len to get hold of how long your string is and start steping throug it one step at the time.
0

progCommented:
That answers all very well, but reject it if you want because I've got the code ready for you!

0

progCommented:
That answers all very well, but reject it if you want because I've got the code ready for you!

0

progCommented:
Private Sub Command1_Click()

Dim i As Integer, stemp As String, sstring As String
Dim n(10) As Integer, j As Integer

i = 1

sstring = "1,2,3,4,5,6"

While i <= Len(sstring)
If Mid(sstring, i, 1) <> "," Then
stemp = stemp & Mid(sstring, i, 1)
Else
MsgBox (stemp)    'store it here
j = j + 1
n(j) = Val(stemp)
stemp = ""
End If
i = i + 1
Wend
MsgBox stemp 'store it here
j = j + 1
n(j) = Val(stemp)

End Sub

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.