|
-
Jan 18th, 2013, 01:11 PM
#1
Thread Starter
Frenzied Member
[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, "|"))
-
Jan 18th, 2013, 01:36 PM
#2
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.
-
Jan 18th, 2013, 01:37 PM
#3
Thread Starter
Frenzied Member
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.
-
Jan 18th, 2013, 01:40 PM
#4
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.
-
Jan 18th, 2013, 01:43 PM
#5
Re: string manipulation
is 'that word' always in the fourth section of your string? (XXXX|XXXX|XXXXX|msexcel|)
-
Jan 18th, 2013, 01:45 PM
#6
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.
-
Jan 18th, 2013, 01:50 PM
#7
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
-
Jan 18th, 2013, 02:07 PM
#8
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)
-
Jan 18th, 2013, 02:16 PM
#9
Thread Starter
Frenzied Member
Re: string manipulation
 Originally Posted by SamOscarBrown
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|