-
VBA Reverse A string
Hi guys,
Im new to this forum as well as the VBA language, I was wondering by any chance if someone can help me with a problem.
I need to figure out a way to reverse a string using the For and Next X format and/or If, Else and Endif.
Any help would work, especially if you can point me in the right direction!
Thanks in advance
-
Why do you need those when VBA has a StrReverse function?
-
-
It's quite simple, get the length of the string variable, then loop from the last character to the first and put into a new variable. Assuming i is the loop control index, the position in the new variable would be i-Len(original_string)+1.
-
I think I would concatenate the new variable and the previous character of the old string
-
Pseudo-code steps
1. Create a string variable (Dim ...) to hold the reversed string for output
2. Use a For / Next / Step loop to step DOWN by -1 from the LEN of the input string to 1 (the first char)
3. For each iteration, add the i-th char from the MID-dle (that is a hint) of the input string to the end of the output string in 1)
Online help is pretty good
-
Just as another thought process for this
You could also look at the RIGHT character of the string then have a temp string that you trim the last character off each iteration and then look at the new RIGHT hand character each time adding to the string. not sure if there is a real benefit but just another approach to the same task :)
Vox190 how did the assignment go?