Results 1 to 6 of 6

Thread: Easy string question **Resolved**

  1. #1

    Thread Starter
    Hyperactive Member maxl's Avatar
    Join Date
    Jan 2002
    Location
    Montréal
    Posts
    384

    Easy string question **Resolved**

    I have a string wich contain two number separated by an undercscore(_). I would like to extract both numbers separatly. Their lenght is variable so I can't use Right and Left functions. Any ideas ?


    Thanks
    Last edited by maxl; Oct 2nd, 2002 at 01:04 PM.
    COBOL sa suce !!!

  2. #2
    Addicted Member Aldragor's Avatar
    Join Date
    Oct 2002
    Location
    Québec, Canada
    Posts
    140
    Check the instr() function!

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    SPLIT!!!

    VB Code:
    1. Dim arr() As Stirng
    2. arr = Split("123_456","_")
    3.  
    4. debug.print arr(1)
    5. debug.print arr(2)
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    Frenzied Member andreys's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,615
    Code:
    num=00123_7478
    
    Number1=left(num,InStr(1,num,"_")-1)
    
    Number2=Mid(num,InStr(1,num,"_")+1)

  5. #5
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    Try this:
    VB Code:
    1. Dim intPos As Integer
    2. Dim strValue As String
    3.  
    4.     strValue = "213_12837"
    5.     intPos = InStr(1, strValue, "_")
    6.     Debug.Print Left(strValue, intPos - 1)
    7.     Debug.Print Mid(strValue, intPos + 1)
    Roy

  6. #6

    Thread Starter
    Hyperactive Member maxl's Avatar
    Join Date
    Jan 2002
    Location
    Montréal
    Posts
    384
    Ok thanks everyone
    COBOL sa suce !!!

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