extracting substrings in VB6

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ashilyas
    New Member
    • Apr 2007
    • 2

    #1

    extracting substrings in VB6

    Hi all,

    I am new to this forum as well as Visual Basic. I haven't been able to find a resource that tells me what functions are available in Visual Basic like you can find the listing in C++ and java. If someone can tell me how to get that it would be great.

    My question though is, I have a string variable in my VB code that has a long string (a combination of smaller strings seperated by ";") I need to extract all theses substrings. They can have variable lengths, so the extraction criteria is the seperator which is the semicolon.
    Can someone please tell me how to do this. Do I have a built in function to do that which I think there should be one. or do I have to code it.

    Thank you
  • iburyak
    Recognized Expert Top Contributor
    • Nov 2006
    • 1016

    #2
    Use Split function which has a delimiter parameter.
    This function returns an array of values which is easy to loop through.


    Try this little example:

    [PHP]Dim sString As String
    Dim arrString
    Dim i As Integer

    sString = "aaaa;bbb;ccccc ;ddd"

    arrString = Split(sString, ";")

    For i = 0 To UBound(arrStrin g)
    Debug.Print arrString(i)
    Next[/PHP]

    Hope it helps.
    Good Luck.

    Comment

    • ashilyas
      New Member
      • Apr 2007
      • 2

      #3
      Thank you very much, it did

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Originally posted by ashilyas
        Thank you very much, it did
        You need to watch out if it's possible (even if unlikely) that the data may contain a ";" within one of the fields.

        Comment

        • ansumansahu
          New Member
          • Mar 2007
          • 149

          #5
          Originally posted by ashilyas
          Hi all,

          I am new to this forum as well as Visual Basic. I haven't been able to find a resource that tells me what functions are available in Visual Basic like you can find the listing in C++ and java. If someone can tell me how to get that it would be great.

          My question though is, I have a string variable in my VB code that has a long string (a combination of smaller strings seperated by ";") I need to extract all theses substrings. They can have variable lengths, so the extraction criteria is the seperator which is the semicolon.
          Can someone please tell me how to do this. Do I have a built in function to do that which I think there should be one. or do I have to code it.

          Thank you
          Hi ,
          I came across this good site that talks about handling strings in VB.

          http://www.aivosto.com/vbtips/stringopt.html

          You can have a look at this for future reference.

          thanks
          ansuman sahu

          Comment

          Working...