Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 140
  • Last Modified:

String parsing

I have a string which contains the below information:

,080800 - Anthelmintics,081202 - Aminoglycosides,081204 - Antifungal Antibiotics

I need to look for a comma in the string and then get only the numbers which follow each comma.

Can you please help with the coding for this.

Thanks
0
meyer1049
Asked:
meyer1049
1 Solution
 
damienmCommented:
If the number always has 6 characters you could use something like below.

Private Sub Command1_Click()
Dim strVal As String
strVal = ",080800 - Anthelmintics,081202 - Aminoglycosides,081204 - Antifungal Antibiotics"
startval = 1
While InStr(startval, strVal, ",")
    MsgBox Mid(strVal, InStr(startval, strVal, ",") + 1, 6)
    startval = InStr(startval, strVal, ",") + 1
Wend
End Sub
0
 
robbertCommented:
Dim arr1 As Variant
Dim arr2 As Variant
Dim strVal As String
Dim i As Integer

strVal = ",080800 - Anthelmintics,081202 - Aminoglycosides,081204 - Antifungal Antibiotics"
strVal = Right(strVal, Len(strVal - 1)

arr1 = Split(strVal, ",")
For i = 0 To UBound(arr1)
    arr2 = Split(arr1(i), " ")
    MsgBox arr2(0)
Next
0
 
damienmCommented:
Robert,

You are missing a ) after Len

strVal = Right(strVal, Len(strVal) - 1)
0
 
deightonCommented:
Dim s As String
Dim lNumbers()
Dim count As Long
Dim sTemp As String
Dim c As Long


s = ",080800 - Anthelmintics,081202 - Aminoglycosides,081204 - Antifungal Antibiotics"""

While InStr(s, ",")
    s = Right(s, Len(s) - InStr(s, ","))
    c = 1
    sTemp = ""
    count = count + 1
    ReDim Preserve lNumbers(count)
   
    While IsNumeric(Mid(s, c, 1))
        sTemp = sTemp & Mid(s, c, 1)
        c = c + 1
    Wend
    lNumbers(count) = Val(sTemp)
Wend


For c = 1 To count
    Debug.Print lNumbers(count)
Next
0
 
smkkaleemCommented:
I used a string array to fill the required number. Also they would be displayed in the Immediate Window. Any questions, please comment

Private Sub Command1_Click()
Dim p_str As String, p_Num(1 To 3) As String, i As Integer, p_intStart As Integer
p_str = ",080800 - Anthelmintics,081202 - Aminoglycosides,081204 - Antifungal Antibiotics"
p_intStart = InStr(1, p_str, ",")
For i = 1 To 3
    p_Num(i) = Trim(Mid(p_str, InStr(p_intStart, p_str, ",") + 1, InStr(InStr(p_intStart, p_str, ","), p_str, "-") - InStr(p_intStart, p_str, ",") - 1))
    p_intStart = InStr(InStr(p_intStart, p_str, ","), p_str, "-")
    Debug.Print p_Num(i)
Next i
End Sub
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now