Reverse a string without using string functions - VBScript

mystr = inputbox("Enter the String:")


'Option 1 - 
Set r=new regexp
 r.pattern ="\w|\W" ' "[a-z 0-9 A-Z]" is equivalent to \w
 r.global=true
 set s=r.execute(mystr)
For each i in s
 revstr = i.value & revstr
Next
MsgBox "Using regexp :" & vbnewline & revstr

'Option 2 - 
cnt = Len(mystr)
For i = 1 to cnt
  revstr = Mid(mystr, i, 1) & revstr
Next
Msgbox "Using Mid function: " & vbnewline & revstr


@Please feel free to comment which will encourage me to write more information in future@

No comments:

Post a Comment