String is nothing but a sequence of characters, where characters can be alphabets or numbers or special characters or all of them.In VB script a variable is a string if it is enclosed within double quotes " ".
'This program is to understand the String Functions present under VB Script.'Function Name Description
'***************************************
'InStr It will return the first occurence of the specified substring. Search will happen from left to right.
'InstrRev It will return the first occurence of the specified substring. Search will happen from Right to Left.
'Lcase It will return lower case of the specified string.
'Ucase It will return Upper case of the specified string.
'Left It will return specific number of characters from the left side of the string.
'Right It will return specific number of characters from the Right side of the string.
'Mid It will return specific number of characters from a string based on the specified parameters.
'Ltrim It will return string after removing the spaces on the left side of the specified string.
'Rtrim It will return string after removing the spaces on the right side of the specified string.
'Trim It will return string value after removing both leading and trailing blank spaces.
'Len It will return the lenght of the given string.
'Replace It will return string after replacing a string with another string.
'Space Fills a string with the specified number of spaces.
'StrComp It will return an integer value after comparing the two specified strings.
'String It will return String with a specified character the specified number of times.
'StrReverse It will return String after reversing the sequece of the characters of the given string.
dim str: str=" This is the Demo String to test all String Functions. "
Dim Data : data=" "
Dim seprator : seprator = vbcrlf & "------------------------------------------" & vbcrlf
Dim searchdata: searchdata = "43"
Dim Result: result="****************************************" & vbcrlf
result = result & " Text = " & str
result=result & vbcrlf &"****************************************" & vbcrlf
result=result &"InStr(5,str,searchdata) :- " & InStr(5,str,searchdata)
'MsgBox "InStr " & InStr(1,str,"string")
'MsgBox "InStr " & InStr(1,str,"string") ' This will return ZERO because s is in small case during search.
'MsgBox "InStr " & InStr(1,str,"Lets",0) ' This wll return ZERO because it is Binaary Search, System is trying to match exact binnary value with which will differ because of different Cases.
'MsgBox "InStr " & InStr(1,str,"Lets",1) ' Search based on the text (ignore case)
result=result & seprator
result=result & "InStrRev :- " & InStrRev(str,"all")
result=result & seprator
result=result & "InStrRev (str,''S'',10,0) :- " & InStrRev(str,"S",10,0)
result=result & seprator
result=result & "InStrRev (str,''S'',10,1) :- " & InStrRev(str,"S",10,1)
result=result & seprator
result=result & "Lcase :- " & Lcase(str)
result=result & seprator
result=result & "Ucase :- " & Ucase(str)
result=result & seprator
result=result & "Left(str,5) :- " & Left (str,5)
result=result & seprator
result=result & "Left(str,15) :- " & Left (str,15)
result=result & seprator
result=result & "Right(str,10) :- " & Right (str,10)
result=result & seprator
result=result & "Right(str,15) :- " & Right (str,15)
result=result & seprator
MsgBox result
result="****************************************" & vbcrlf
result = result & " Text = " & str
result=result & vbcrlf &"****************************************" & vbcrlf
result=result & "Mid(str,5) :- " & Mid (str,5)
result=result & seprator
result=result & "Mid(str,5,15):- " & Mid (str,5,15)
result=result & seprator
result=result & "Ltrim(str):- " & LTrim(str)
result=result & seprator
result=result & "RTrim(str):- " & RTrim(str)
result=result & seprator
result=result & "Len(str):- " & Len(str)
result=result & seprator
result=result & "Replace(str, Demo,Test):- " & Replace(str, "Demo","Test")
result=result & seprator
result=result & "Replace(str,s,#,1,2):- " & Replace(str, "s","#",1,2) ' 's' is replaced by # for the next 2 occurences.
result=result & seprator
result=result & "space(5):-" & space(5)& str
result=result & seprator
MsgBox result
result="****************************************" & vbcrlf
result = result & " Text = " & str
result=result & vbcrlf &"****************************************" & vbcrlf
result =result & "StrComp(Microsoft,Microsoft) :-"& StrComp("Microsoft","Microsoft")
result =result & seprator
result =result & "StrComp(Microsoft,MICROSOFT):- " & StrComp("Microsoft","MICROSOFT")
result =result & seprator
result =result & "StrComp(Microsoft,MiCrOsOfT):-"& StrComp("Microsoft","MiCrOsOfT")
result =result & seprator
result =result & "StrComp(Microsoft,MiCrOsOfT,1):- " & StrComp("Microsoft","MiCrOsOfT",1)
result =result & seprator
result =result & "StrComp(Microsoft,MiCrOsOfT,0):- "& StrComp("Microsoft","MiCrOsOfT",0)
result =result & seprator
result =result & "String(4,''*''):- "& String(4,"*")
result =result & seprator
result =result & "StrReverse(str):- "& StrReverse(str)
result =result & seprator
MsgBox result