Results 1 to 9 of 9

Thread: [RESOLVED] string manipulation

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Resolved [RESOLVED] string manipulation

    Hi guys, I have this following string:

    "testing|test|Name|msword|Looking|aaa"

    I want to be able to get the "msword" out of that above string after the "Name|"

    Also, if the string becomes like this:

    "testing|test|Name|msword|"

    I want to be able to get the "msword" out of that above string after the "Name|" as well -

    so the format will be always Name|something....

    I tried this, but it only works for 2nd scenario but no the first scenario.

    Code:
    Right$(sCommand, Len(sCommand) - InStrRev(sCommand, "|"))

  2. #2
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: string manipulation

    What do you mean by 'out'? You want it out (removed) of the string or you want to just capture it into another variable. Also is 'msword' a fixed value or what?

    If you want to remove it then use Replace function.

    Dim s1 As String

    s1 = "testing|test|Name|msword|Looking|aaa"

    s1 = Replace(s1,"msword", "")


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Re: string manipulation

    When I said "out", I meant display it to the users - using msgbox -
    That msword will be dynamic. So it can be msexcel, outlook, or other app names. I do not want to replace or remove.

  4. #4
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: string manipulation

    Is Name fixed


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  5. #5
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,624

    Re: string manipulation

    is 'that word' always in the fourth section of your string? (XXXX|XXXX|XXXXX|msexcel|)

  6. #6
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: string manipulation

    Look at his 1st example, Sam


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  7. #7
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,624

    Re: string manipulation

    does this do it for you?
    Dim mystring() As String, myWord As String, myInt As Integer
    mystring = Split(Text1.Text, "Name|")
    myInt = InStr(1, mystring(1), "|")
    myWord = Mid(mystring(1), 1, myInt - 1)
    MsgBox myWord
    End Sub

  8. #8
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: string manipulation

    Here's another approach:

    Code:
    Private Function GetText(ByRef sText As String) As String
        Dim Pos As Long
    
        Pos = InStr(sText, "Name|") + 5&
        GetText = Mid$(sText, Pos, InStr(Pos, sText, "|") - Pos)
    End Function
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Re: string manipulation

    Quote Originally Posted by SamOscarBrown View Post
    does this do it for you?
    Dim mystring() As String, myWord As String, myInt As Integer
    mystring = Split(Text1.Text, "Name|")
    myInt = InStr(1, mystring(1), "|")
    myWord = Mid(mystring(1), 1, myInt - 1)
    MsgBox myWord
    End Sub
    Thanks, this solution works!

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