Results 1 to 4 of 4

Thread: return a portion of a string value

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    3
    I I have a string and I would like to only use a portion of the string, what function should I use?

    For example:
    strString = "This is fun!"

    I want to use "This is" only

    How would I cut off everthing after "_f" and only use "This is"

    Thanks for any help, VolFans

  2. #2
    Addicted Member
    Join Date
    Sep 2000
    Posts
    138
    Left$(strString,InstrRev(strString," ")-1)

    -------------------------------
    Visual Basic Professional 6.0

  3. #3
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754

    Dim strArray() As String
    Dim strTest as String

    strTest = "This Is A Test"
    'Use the Split Function
    strArray = Split(strTest, " ")
    MsgBox strArray(1)
    MsgBox strArray(2)


    HTH
    Crispin
    VB6 ENT SP5
    VB.NET
    W2K ADV SVR SP3
    WWW.BLOCKSOFT.CO.UK

    [Microsoft Basic: 1976-2001, RIP]

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    'slight drawback..it finds the first f
    'that could be a problem
    
    Option Explicit
    
    Private Sub Command1_Click()
    
        Dim SearchString, SearchChar, MyPos
        SearchString = "This is fun."  ' String to search in.
        SearchChar = "f"
    
    
        MyPos = InStr(1, SearchString, SearchChar, 1)
    
    'if found MyPos will be > 0
        If MyPos > 0 Then
            SearchString = Left(SearchString, MyPos - 1)
            SearchString = Trim(SearchString)
            MsgBox SearchString
                
        End If
    
    End Sub

    [Edited by HeSaidJoe on 10-05-2000 at 01:02 PM]
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

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