|
List of free |
| Remove non alphanumeric characters from script |
In order to remove non alphanumeric characters from a string we have used Replace and CHR commands.
Replace(string1,string2,string3) command will replace string2 by string3 in string.
For example:
The code: <% =Replace("I love John","John","Peter") %>
Output: I love Peter
CHR(integer) will return the ANSI character code specified by integer (must be 0 to 256). Values for integer to get alphanumeric characters are between 48-57(numbers), 65-90 (all caps letters) and 97-122 (small caps letters).
For example:
The code: <% =CHR(48) %>
Output: 0
The code: <% =CHR(65) %>
Output: A
The code: <% =CHR(97) %>
Output: a
Additionally, ANSI character for CHR(32) is space.
Check all ANSI character for CHR(integer) here.
In the script bellow will remove all non-alphanumeric or spaces from
variable Thetext. Ourput is in the right.
| Remove non-alpha numeric characters from "Thetext" | Output |
| <%
Thetext="#$%a sa&*dd.,;: ggg" for i=0 to 31 Thetext=Replace(Thetext,CHR(i),"") next for i=33 to 47 Thetext=Replace(Thetext,CHR(i),"") next for i=58 to 64 Thetext=Replace(Thetext,CHR(i),"") next for i=91 to 96 Thetext=Replace(Thetext,CHR(i),"") next for i=123 to 255 Thetext=Replace(Thetext,CHR(i),"") next Response.write (Thetext) %> |
a sadd ggg |
|
|
Create word search puzzles with your own words
|
2008@ AspTutorial.info. All rights reserved.