Solved

String parsing

Posted on 2001-06-04
5
136 Views
Last Modified: 2010-05-02
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
Comment
Question by:meyer1049
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 2

Accepted Solution

by:
damienm earned 30 total points
ID: 6153142
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
 
LVL 15

Expert Comment

by:robbert
ID: 6153163
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
 
LVL 2

Expert Comment

by:damienm
ID: 6153204
Robert,

You are missing a ) after Len

strVal = Right(strVal, Len(strVal) - 1)
0
 
LVL 18

Expert Comment

by:deighton
ID: 6153293
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
 
LVL 2

Expert Comment

by:smkkaleem
ID: 6153318
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question