Results 1 to 4 of 4

Thread: Searhing Data in String

  1. #1

    Thread Starter
    Fanatic Member mutley's Avatar
    Join Date
    Apr 2000
    Location
    Sao Paulo - Brazil
    Posts
    709

    Searhing Data in String

    Hi

    How can I to Find a Data in String ?

    VB Code:
    1. ("AC","ADM","AL","ALA","ALT","AN","ANT","AP","AR","AT","B","BAN","BI","BL","BOX","BX", _
    2.                       "C","CA","CAB","CAL","CAN","CD","CH","CJ","CL","CO","COB","CS","D","E","ED","EP","ESC", _
    3.                       "F","FAZ","FR","FU","GAL","GAR","GB","GJ","GP","GT","GUI","HAR","HG","JD","KM","LA","LJ", _
    4.                      "LO","LT","MZ","OF","PA","PAD","PAS","PD","PI","POR","PRO","PRT","PT","PTE","PTO","PV", _
    5.                                       "QD","QS","REC","RES","SG","SIT","SJ","SL","SLO","SS","ST","STD","TE","TOR","TR","TRV","TYI", _
    6.                                       "VLA","X","ZEL")

  2. #2
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Re: Searhing Data in String

    First, test it to make sure the desired result is in the string.
    I'll use "CO" as my example:
    VB Code:
    1. If InStr(myStr, "CO") > 0 Then
    If that returns a value greater than 0, a.k.a. your search exists, probably the easiest thing to do would be to break it into an array and search each value:
    VB Code:
    1. Dim myArray() As String
    2. myArray = Split(myStr, ",")
    3. For i = 0 to UBound(myArray)
    4.    If myArray(i) = "CO" Then
    5.       'your code here
    6.    End If
    7. Next i

  3. #3
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Searhing Data in String

    Shouldn't it be:
    VB Code:
    1. '...
    2.    If myArray(i) = [U]Chr(34) &[/U] "CO" [U]& Chr(34)[/U] Then
    3.       'your code here
    4.    End If
    5. '...
    ?

  4. #4
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Re: Searhing Data in String

    Good call. We could always get rid of the quotes in the string before we split it... that would eliminate that problem...
    VB Code:
    1. myStr = Replace(myStr, chr(34), "")
    Then run it through my subs...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width