|
|
|
|
Building You can join text strings with the & sign. E.g. "This is a short and" & " meaning less sentence" will join the two strings into "This is a short and meaning less sentence". You can also join text with variables. E.g. "The time is " & time & " right now" will give you this sentence: "The time is 12:50:15 PM right now". You can also join arrays: <% DIM MyArray(2) MyArray(0) = "This is " MyArray(1) = "a little " MyArray(2) = "sentence." Sentence = JOIN(MyArray) %> The output of sentence would be: "This is a little sentence." Extract To extract a part of the content of a string, use Left, Mid or Right. Left returns a certain number of characters counting from the left. The Right function is identical with Left, except it counts from the right. The Mid function returns the part starting at the specified number of places from the left, and stopping after the specified length. Left("This is a little sentence.",4) returns "This" Right("This is a little sentence.",16) returns "little sentence." Mid("This is a little sentence.",6,4) returns "is a" Replace One of the most useful functions is the replace function. You can use it to locate and replace a part of one string with another string. E.g. to replace all the occurrences of # in a string with !, you just write: Replace("This is a good site# It rules#","#","!") returning "This is a good site! It rules!" Search To search a string for the first occurrence of another string, use the InStr function, it will return the position of the string. InStr("Hi there stranger!","there") returns 4 InStr("Hi there stranger!","THERE") returns 0 InStr will hunt for the first match, but you can specify to start hunting from a specified position. InStr("There is some one there, is it not?","is") returns 7 InStr(8,"There is some one there, is it not?","is") returns 26 Compare To compare two strings, you can use = or StrComp. = is case sensitive, e.g. "peach" = "PEACH" is false. Use LCase or UCase to work around this: UCase("peach") = UCase("PEACH") is true. The StrComp is used like this: StrComp(string1,string2) and returns 0 if they are the same (else 1). StrComp is also case sensitive, but you can add a parameter to change this: StrComp(string1,string2,1) |