/ Published in: ASP
A small collection of the most wanted string-functions in ASP / VB.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
' Count the chars in a string ' ========= response.write(len("1234567")) ' Output: 7 ' ========= ' Edit date ' ========= DateAdd(Interval, Amount, yourDate) DateAdd("ww", 2, now) DateAdd("ww", -2, now) ' Value Description ' ============================ ' yyyy Year ' q Quarter ' m Month ' y Day of the year ' d Day ' w Weekday ' ww Week of a year ' h Hour ' n Minute ' s Second ' ========= ' Search in string ' ========= foo = "12.34" response.write(instr(foo, ".")) ' Output: 3 ' ========= ' Cut string ' ========= response.write(left("1234567", 3)) ' Output: 123 response.write(right("1234567", 3)) ' Output: 567 response.write(mid("1234567", 3, 2)) ' Output: 34 response.write(mid("1234567", 3)) ' Output: 567 ' ========= ' String into float ' ========= String = "12,26" Float = CDbl(String) Result = Float + 7.74 ' ========= ' String into int ' ========= String = "12,26" Int = CInt(String) Result = Int + 7.74 ' ========= ' Split string ' ========= foo = "My-Name" bar = split(foo, "-") response.write(bar(0) & " " & bar(1)) ' Output: My Name ' ========= ' Replace' ========= foo = "My-Name" response.write(replace(foo,"-"," ")) ' Output: My Name ' =========