Results 1 to 6 of 6

Thread: read string and extract

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Location
    Bosnia and Herzegovina
    Posts
    65

    read string and extract

    Hi,

    I have the following string:
    "<1>Company</1><a1>Name</a>"

    What I need is to extract Company and Name only.

    any ideas?

    regards

  2. #2
    Frenzied Member
    Join Date
    Oct 2003
    Posts
    1,301

    Re: read string and extract

    Are all strings you need to process in that exact format and sequence?
    Find the position of "><" with InStr, use Left, Right or Mid to cut it into two strings and then remove the tags.

  3. #3
    Member
    Join Date
    Sep 2006
    Posts
    37

    Re: read string and extract

    Yes, if the tags are exactly that way, then yes, he could use instr. But what if not?

    I quickly typed this out ...

    VB Code:
    1. Dim RecordData As String
    2.     Dim FieldData() As String
    3.     Dim intA As Integer
    4.     Dim InsideHTMLTag As Boolean
    5.     ReDim FieldData(0)
    6.     RecordData = "<1>Company</1><a1>Name</a>"
    7.     InsideHTMLTag = False
    8.     For intA = 1 To Len(RecordData)
    9.         Select Case Mid(RecordData, intA, 1)
    10.             Case "<"
    11.                 InsideHTMLTag = True
    12.             Case ">": InsideHTMLTag = False
    13.                 If FieldData(UBound(FieldData)) <> "" And intA < Len(RecordData) Then
    14.                     ReDim Preserve FieldData(UBound(FieldData) + 1)
    15.                 End If
    16.             Case Else
    17.                 If InsideHTMLTag = False Then
    18.                     FieldData(UBound(FieldData)) = FieldData(UBound(FieldData)) & Mid(RecordData, intA, 1)
    19.                 End If
    20.         End Select
    21.     Next intA

    It works on your given example, using the < and > symbols as markers to determine whether it's in or out of a tag. Then it puts the data into the FieldData array. Pull the data out of the array starting at 0. It should work to split any data that is outside of HTML tags. Let me know how it works.

  4. #4
    Addicted Member
    Join Date
    Mar 2002
    Location
    Lithuania
    Posts
    165

    Re: read string and extract

    you can always use regular expressions
    P.S. Sorry for my poor English...

  5. #5
    Member
    Join Date
    Sep 2006
    Posts
    37

    Re: read string and extract

    Quote Originally Posted by GameBit
    you can always use regular expressions
    GameBit ... You would do this how? Can you provide an example that would work with greenba's data?

  6. #6
    Addicted Member
    Join Date
    Mar 2002
    Location
    Lithuania
    Posts
    165

    Re: read string and extract

    Attachment...
    Attached Files Attached Files
    P.S. Sorry for my poor English...

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