Tuesday, May 11, 2010

How to reverse a string using vbscript

str="uday"
For i=len(str) to 1 step -1
strchar=mid(str,i,1)
resultstr=resultstr&strchar
Next
msgbox resultstr

or you can use the built-in function in vbscript
msgbox strreverse("uday")

2 comments:

Anem Udaya Kumar said...

Thanks for your post J B C.

But i wanted to know what that pattern means?

r.pattern="[a-z A-Z]"

Deep said...

This pattern means that it will reverse any string which contains range of letters from a to z and A to Z and also range of numericals from 0 to 9.
So, if you keep your pattern like "[a-z A-Z]" and suppose you give your string as "QUeR123y"; so your answer will be "yReUQ". It will not consider the numbers since you skipped them when you defined your pattern.
I hopr you got it.