String Functions
'==========================================================================
' NAME: StringFunctions1.vbs
' Authors: Neal Walters
' http://VBScript-Training.com
'==========================================================================
text1 = "We the people of the United States, in order to form the a more perfect union..."
' 1...5...10....5...20..
WScript.Echo "Text1=" & text1
WScript.Echo "Length=" & Len(text1)
WScript.Echo "Left(text1,2)=" & Left(text1,2)
WScript.Echo "Right(text1,8)=" & Right(text1,8)
WScript.Echo "Mid(text1,8,6)=" & Mid(text1,8,6)
WScript.Echo "InStr(text1,""United"")=" & InStr(text1,"United")
posFirstThe = InStr(text1,"the")
posSecondThe = InStr(posFirstThe+1,text1,"the")
posLastThe = InStrRev(text1,"the")
WScript.Echo "Position first 'the' = " & posFirstThe
WScript.Echo "Position second 'the' = " & posSecondThe
WScript.Echo "Position last 'the' = " & posLastThe
WScript.Echo String(70,"-")
userInput = " Neal Walters "
WScript.Echo "userInput='" & userInput & "'"
WScript.Echo "ltrim(userInput)='" & ltrim(userInput) & "'"
WScript.Echo "rtrim(userInput)='" & rtrim(userInput) & "'"
WScript.Echo "trim(userInput)='" & trim(userInput) & "'"
WScript.Echo String(70,"-")
'==========================================================================
' Authors: Neal Walters
' http://VBScript-Training.com
'==========================================================================
text1 = "John,Doe,123 Main Street,Dallas,TX,75080"
' 1...5...10....5...20..
WScript.Echo "Text1=" & text1
myWords = Split(text1,",")
For Each word In myWords
WScript.Echo word
Next
WScript.Echo String(70,"-")
For j = 0 To UBound(MyWords)
WScript.Echo "J=" & j & " myWords(j) = " & myWords(j)
Next
WScript.Echo String(70,"-")
Firstname = myWords(0)
Lastname = myWords(1)
Address = myWords(2)
City = myWords(3)
State = myWords(4)
Zip = myWords(5)
WScript.Echo "City=" & City & " Zip=" & Zip
text2 = Join(myWords,"/")
WScript.Echo "Text2=" & text2
text3 = Replace(text2,"/","-")
WScript.Echo "Text3=" & text3
text4 = "05/10/2004"
WScript.Echo Replace(text4,"/","-")
|