|
-
Feb 7th, 2013, 04:00 PM
#1
Thread Starter
Frenzied Member
string reverse?
I am having string issue. I am trying reverse the string, but cannot seem to accomplish.
Scenario:
The string is dynamic - def, abc - I want the out put as message box to be abc def
If the string is def, abc 123 - I want the out put to be abc 123 def
Is it posssible to reverse string with vb6?
-
Feb 7th, 2013, 04:13 PM
#2
Re: string reverse?
Yes it is possible. In this case you may want to use the Split() function to break the string into an array using the space as a seperator then loop through the resulting array back to front appending the items to a new string.
Something like this for example
Code:
Private Sub Command1_Click()
Dim MyString As String
Dim MyArray() As String
MyString = "def, abc 123"
MyArray = Split(MyString, " ")
MyString = ""
Dim x As Integer
For x = UBound(MyArray) To 0 Step -1
MyString = Trim(MyString & " " & MyArray(x))
Next
MsgBox MyString
End Sub
Last edited by DataMiser; Feb 7th, 2013 at 04:17 PM.
-
Feb 7th, 2013, 04:14 PM
#3
Re: string reverse?
That's not really reversing a string. A reversed string would be if def = abc 123 then reversed is 321 cba
What you're asking is how to switch each element around.
Dim a() As String
Dim s as string
a = Split(def,Space(1))
s = a(1) & Space(1) & a(0)
Last edited by jmsrickland; Feb 7th, 2013 at 04:20 PM.
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.
-
Feb 7th, 2013, 04:14 PM
#4
Re: string reverse?
StrReverse reverses the character order of the specified string, but that doesn't seem to be what you need.
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)
-
Feb 7th, 2013, 04:17 PM
#5
Thread Starter
Frenzied Member
Re: string reverse?
Oh yes sorry. Thanks for giving me some insights. I found this :
http://www.devx.com/vb2themax/Tip/19218
-
Feb 7th, 2013, 04:18 PM
#6
Re: string reverse?
see post number 2. I edited it to add a simple example
-
Feb 7th, 2013, 04:22 PM
#7
Re: string reverse?
 Originally Posted by vbbit
I am having string issue. I am trying reverse the string, but cannot seem to accomplish.
Scenario:
The string is dynamic - def, abc - I want the out put as message box to be abc def
If the string is def, abc 123 - I want the out put to be abc 123 def
Is it posssible to reverse string with vb6?
Are you sure? I would think you want 123 abc def
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.
-
Feb 7th, 2013, 05:16 PM
#8
Re: string reverse?
is it me or there is a comma??
i would split with
dim a() as string
a = split(string,", ")
string = a(1) & Space(1) & a(0)
Last edited by Max187Boucher; Feb 7th, 2013 at 05:22 PM.
-
Feb 7th, 2013, 05:21 PM
#9
Re: string reverse?
I thought def was the name of the string, lol. I see now it is just another element. So, yes, split on comma
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.
-
Feb 7th, 2013, 05:23 PM
#10
Re: string reverse?
Aye Max, Based upon what OP SAYS he wants, then the comma would be used to split the string into TWO strings, not three....sometimes hard to determine JUST what an OP wants.
-
Feb 7th, 2013, 05:27 PM
#11
Re: string reverse?
hey sam sorry i dont get the three strings?? maybe i am not reading your post properly
-
Feb 7th, 2013, 05:36 PM
#12
Re: string reverse?
Hey Max, no, I just saw that jms and datam might have misread OPs intent....(as did I when first looking at it). They both suggested (I THINK) to split the string into three strings, not two. YOUR post is correct (I think) as to what OP wants.
-
Feb 7th, 2013, 05:45 PM
#13
Re: string reverse?
ahh yes with the split space it does make three strings
-
Feb 7th, 2013, 10:34 PM
#14
Re: string reverse?
Who knows... the way the OP is worded is very difficult to be sure.
-
Feb 8th, 2013, 12:15 AM
#15
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
|