String Length with Len() and LenB()

Len() returns the number of characters in a string. Spaces are characters too, even when consecutive spaces are collapsed visually by normal HTML rendering.

Count characters

Dim my_string
my_string="Welcome to Plus2net.com"
Response.Write my_string
Response.Write "<br>Length of this string = " & Len(my_string)

Output

Welcome to Plus2net.com
Length of this string = 23

Leading spaces count

my_string="   Welcome to Plus2net.com"
Response.Write my_string
Response.Write "<br>Length of this string = " & Len(my_string)

Output

Welcome to Plus2net.com
Length of this string = 26

The browser collapses consecutive spaces in normal HTML, but Len() still counts the three leading spaces.

LenB() and byte-oriented length

my_string="Welcome to Plus2net.com"
Response.Write my_string
Response.Write "<br>Length of this string = " & Len(my_string)
Response.Write "<br>Byte-oriented length = " & LenB(my_string)

Legacy example output

Welcome to Plus2net.com
Length of this string = 23
Byte-oriented length = 46
LenB note: LenB() is byte-oriented and may differ from Len() for Unicode/DBCS data. Do not treat a fixed 2-bytes-per-character result as a portable rule for storage, network payload size, or UTF-8 length.

ASP Home






✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer