Saturday 29 August 2015

Reverse a String, Array, Sort an Array, and other basics

MsgBoxLen(str)

str1 = "v"
MsgBoxLen(str1)

str2 = "venu"
MsgBoxInStr(1,str2, "3", 1)

str = "venu"
For i=Len(str) To1Step -1
    str3  = str3 & Mid(str, i, 1)
Next
MsgBox str3

MsgBoxStrReverse("hi")

MsgBox"lower to upper"

MsgBoxAsc("a") & "/" & Asc("z")

str1= "Venu Gopi"
str2 = ""
For i = 1ToLen(str1)
    char = Mid (str1, i,1)   
    IfAsc(char)>=97andAsc(char)<=122Then
        str2 = str2 & UCase(char)
    Else
        str2 = str2 & LCase(char)
    EndIf
Next
MsgBox str2

MsgBox"Regular Expression.."
str1 =  "Venu GOpala krishna GOPI"
str2 =""
Set reg = NewRegExp
reg.pattern ="[a-z]"
reg.global = True
reg.ignoreCase = False
For i = 1ToLen(str1)
    c = Mid(str1, i, 1)
    flag  = reg.test(c)
    If flagThen  
        str2 = str2 & UCase(c)
    Else
        str2 = str2 & LCase(c)
    EndIf
Next

MsgBox str2

--------------------------------
Version:0.9 StartHTML:00000107 EndHTML:00004204 EndFragment:00004164 EndFragment:00000000 ''Reverse An Array

a = Array(1,2,3,5,8,9,10,11)
printArray(a)
Sub printArray(arrData)
    For i =0ToUBound(arrData)
        s = s & arrData(i) & "-"
    Next
    MsgBox s
EndSub


x = UBound(a)
For i = 0To x/2
    temp = a(i)
    a(i) = a(x)
    a(x) = temp
    x= x-1
Next

printArray(a)

=====================================
a = Array(2,3,5,1,6,9,12,14,13)

MsgBox"Sorting an array"
printArray(a)

x = UBound(a)
For i= 0To x-1
    For j=0To i
        If a(j)>a(j+1) Then
            temp = a(j)
            a(j) = a(j+1)
            a(j+1) = temp
        EndIf
    Next
Next
printArray(a)   

Sub printArray(arrData)
    For i =0ToUBound(a)
    s = s & a(i) & "-"
    Next
    MsgBox s
EndSub

No comments:

Post a Comment