|
-
May 14th, 2006, 07:36 PM
#1
Thread Starter
Addicted Member
[RESOLVED] string manipulation help
sample string: "123456 - Popo"
i want to know on how to get my final result like this:
variable1 = "123456"
variable2 = "Popo"
thanks!
-
May 14th, 2006, 07:43 PM
#2
Re: string manipulation help
VB Code:
'You can use the split function:
Dim strTest As String
Dim strSplits() As String
strTest = "123456 - Popo"
strSplits = Split(strTest)
Debug.Print strSplits(0)
Debug.Print strSplits(2)
-
May 14th, 2006, 07:46 PM
#3
Thread Starter
Addicted Member
Re: string manipulation help
-
May 14th, 2006, 07:46 PM
#4
Re: string manipulation help
VB Code:
'Another way:
Dim strTest As String
Dim intPos As Integer
strTest = "123456 - Popo"
intPos = InStr(1, strTest, " ")
'Debug.Print intPos
Debug.Print Left$(strTest, intPos - 1)
intPos = InStrRev(strTest, " ")
'Debug.Print intPos
Debug.Print Right$(strTest, Len(strTest) - intPos)
-
May 14th, 2006, 07:47 PM
#5
PowerPoster
Re: string manipulation help
VB Code:
strArray = "123456-Popo"
strArray = Split(strArray, "-")
Variable1 = strArray(0)
Variable2 = strArray(1)
OR
VB Code:
strArray = "123456-Popo"
strArray = Split("-" & strArray, "-")
Variable1 = strArray(1)
Variable2 = strArray(2)
OR
VB Code:
strArray = "123456-Popo"
strArray = Split("-" & strArray, "-")
For e = 1 to UBound(strArray)
Variable(e) = strArray(e)
Next e
-
May 14th, 2006, 07:47 PM
#6
Re: string manipulation help
There are multiple ways of parsing so here one:
VB Code:
Private Sub Command1_Click()
Dim sText As String
Dim res1$, res2$
sText = "123456 - Popo"
res1 = Trim(Left(sText, InStr(1, sText, "-") - 1))
res2 = Trim(Mid(sText, InStr(1, sText, "-") + 1))
Debug.Print res1
Debug.Print res2
End Sub
-
May 14th, 2006, 07:51 PM
#7
Thread Starter
Addicted Member
Re: string manipulation help
thanks a lot for the help guys!
-
May 14th, 2006, 08:16 PM
#8
Thread Starter
Addicted Member
Re: string manipulation help
 Originally Posted by RhinoBull
There are multiple ways of parsing so here one:
VB Code:
Private Sub Command1_Click()
Dim sText As String
Dim res1$, res2$
sText = "123456 - Popo"
res1 = Trim(Left(sText, InStr(1, sText, "-") - 1))
res2 = Trim(Mid(sText, InStr(1, sText, "-") + 1))
Debug.Print res1
Debug.Print res2
End Sub
i got an error in this with this example string "123456 - Popo-Cost"
result1 = "123456 - Popo"
result2 = "Cost"
the result must be
result1 = "123456"
result2 = "Popo-Cost"
cheers
-
May 14th, 2006, 10:07 PM
#9
Re: [RESOLVED] string manipulation help
If you want consistent output you have to have consistent input. Or, the old saying - garbage in, garbage out.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
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
|