VBScript AscFunction
Complete VBScript Reference Manual
The Asc function converts the first letter in a string to the corresponding ANSI code and returns the result.
Syntax
Asc(string)
| Parameters | Description |
|---|---|
| string | Required. String expression. Cannot be an empty string! |
Examples
Example 1
<script type="text/vbscript">
document.write(Asc("A") & "<br />")
document.write(Asc("a") & "<br />")
document.write(Asc("F") & "<br />")
document.write(Asc("f") & "<br />")
document.write(Asc("2") & "<br />")
document.write(Asc("#") & "<br />")
</script>
document.write(Asc("A") & "<br />")
document.write(Asc("a") & "<br />")
document.write(Asc("F") & "<br />")
document.write(Asc("f") & "<br />")
document.write(Asc("2") & "<br />")
document.write(Asc("#") & "<br />")
</script>
The above example outputs:
65
97
70
102
50
35
97
70
102
50
35
Try it »
Example 2
Asc returns the ANSI code of the first character in a string:
<script type="text/vbscript">
document.write(Asc("o") & "<br />")
document.write(Asc("example.com"))
</script>
document.write(Asc("o") & "<br />")
document.write(Asc("example.com"))
</script>
The above example outputs:
111
114
114
Try it »
Example 3
How to return the ANSI codes of all characters in a string:
<script type="text/vbscript">
txt="example.com"
for i=1 to len(txt)
document.write(Asc(mid(txt,i,1)) & "<br />")
next
</script>
txt="example.com"
for i=1 to len(txt)
document.write(Asc(mid(txt,i,1)) & "<br />")
next
</script>
The above example outputs:
114
117
110
111
111
98
46
99
111
109
117
110
111
111
98
46
99
111
109
Try it »
Complete VBScript Reference Manual Other Extensions