Sideway BICK BlogSideway BICK BLOG from Sideway

A Sideway to Sideway Home

Link:http://output.to/sideway/default.asp?qno=180300010

Script, Scripting Language, VBScript elements, Server-Side VBScript Function Len, LenB Function

VBScript String Functions

Functions for manipulating string expression.

Len Function

last updated 9/20/2017

Create a number from a given string or a specified variable by counting the number of characters in the given string or the specified variable.

Syntax

Len(string | varname)

Argument

stringRequired if varname is omitttd. Any valid string expression that is used for counting the number of characters.varnameRequired if string is omitttd.Any valid variable name that is used for evaluating the number of characters.

Returns

Returns a Variant of the Long data subtype containing the number obtained from a given string or a specified variable by counting the number of characters in the given string or the specified variable.

Special returns of Len function:

string/varnamereturn valueNullNullEmpty0""0

Remarks

  • The Len function is used for manipulating character of a string expression, the number of characters is returned. The LenB function is used for manipulating byte data of a string expression, the number of characters returned is in terms of number of bytes.

Requirement

1

LenB Function

last updated 9/20/2017

Create a number from a given string or a specified variable by counting the number of bytes in the given string or the specified variable.

Syntax

LenB(string | varname)

Argument

stringRequired if varname is omitttd. Any valid string expression that is used for counting the number of bytes.varnameRequired if string is omitttd.Any valid variable name that is used for evaluating the number of bytes.

Returns

Returns a Variant of the Long data subtype containing the number obtained from a given string or a specified variable by counting the number of bytes in the given string or the specified variable.

Special returns of Len function:

string/varnamereturn valueNullNullEmpty0""0

Remarks

  • The Len function is used for manipulating character of a string expression, the number of characters is returned. The LenB function is used for manipulating byte data of a string expression, the number of characters returned is in terms of number of bytes.
  • However, the behavior of VBScript functions such as MidB, ChrB, LeftB, LenB, ChrB and AscB depends on the byte ordering of the hardware platform, and the number of bytes used to represent Unicode characters in the system software. The functions may produce different results on different operating systems.

Requirement

1

Examples

Examples of Len function

ASP VbScript Command:
<script runat="server" language="VBScript">
Dim vars,str,cmda,var:var=0
cmda=array("str","Len(str)","LenB(str)")
Dim ucnt,tmp,i:ucnt=UBound(cmda):If var=1 Then:tmp="":Else:tmp="<b>vars</b>":End If:For i=0 to ucnt:tmp=tmp&"<b>"&rmv_ctrl(cmda(i))&", TypeName</b>":Next:Response.Write "Results on Microsoft Windows 8.1 Pro x64, Microsoft-IIS/8.5, VBScript Version 5.8 of page /internet/users/sideblog/default.asp<br />"&"<i>"&tmp&"</i>"
Function dsp_x:Dim tmp_a,tmp_b,i:If varx=0  Then:Execute vars:End If:If var=1 Then:tmp_a="":Else:tmp_a=rmv_ctrl(vars):End If:For i=0 to ucnt:tmp_b=cmd_b(cmda(i)):if i/2=fix(i/2) Then:tmp_b="<b>"&tmp_b&"</b>":End If:tmp_a=tmp_a&tmp_b:Next:Response.Write "<i>"&tmp_a&"</i>":End Function
Function rmv_ctrl(blk_str):Select Case blk_str:Case chr(0):blk_str="NUL":Case chr(1):blk_str="SOH":Case chr(2):blk_str="STX":Case chr(3):blk_str="ETX":Case chr(4):blk_str="EOT":Case chr(5):blk_str="ENQ":Case chr(6):blk_str="ACK":Case chr(7):blk_str="BEL":Case chr(8):blk_str="BS":Case chr(9):blk_str="HT":Case chr(10):blk_str="LF":Case chr(11):blk_str="VT":Case chr(12):blk_str="FF":Case chr(13):blk_str="CR":Case chr(14):blk_str="SO":Case chr(15):blk_str="SI":Case chr(16):blk_str="DLE":Case chr(17):blk_str="DC1":Case chr(18):blk_str="DC2":Case chr(19):blk_str="DC3":Case chr(20):blk_str="DC4":Case chr(21):blk_str="NAK":Case chr(22):blk_str="SYN":Case chr(23):blk_str="ETB":Case chr(24):blk_str="CAN":Case chr(25):blk_str="EM":Case chr(26):blk_str="SUB":Case chr(27):blk_str="ESC":Case chr(28):blk_str="FS":Case chr(29):blk_str="GS":Case chr(30):blk_str="RS":Case chr(31):blk_str="US":Case chr(127):blk_str="DEL":End Select:rmv_ctrl=blk_str:If IsNull(blk_str) OR IsEmpty(Blk_str) OR blk_str="" OR IsNumeric(Blk_str) Then:Else:rmv_ctrl=Replace(Replace(Replace(Replace(Replace(blk_str,"&","&amp;"),"  "," &nbsp;"),"""","&quot;"),"<","&lt;"),">","&gt;"): End If :End Function
Function cmd_b(blk_str):cmd_b="["&cmd_x(blk_str)&"], "&cmd_x("TypeName("&blk_str&")"):End Function
Function cmd_x(blk_str):On Error Resume Next:Dim xans, tmp:xans="":tmp="":execute "xans="&blk_str:If Err.Number <> 0  Then:xans=cmd_x("TypeName("&blk_str&")"):Select Case xans:Case 9::Case Else:xans="error":End Select:End If:If IsArray(xans)=False Then:cmd_x=rmv_ctrl(xans): Else:tmp=lst_arry(xans):cmd_x=trim(tmp):End If:End Function
Function lst_arry(blk_str):Dim tmp,i,q:q="""":tmp="":For i=0 to UBound(blk_str):if VarType(blk_str(i))>1 And VarType(blk_str(i))<6 Then:q="'":End If:tmp=tmp&" "&q&rmv_ctrl(blk_str(i))&q:Next:lst_arry=trim(tmp):End Function

vars="str=Null":dsp_x
vars="str=Empty":dsp_x
vars="str=""""":dsp_x
vars="str="" """:dsp_x
vars="str=a":dsp_x
vars="str=""  """:dsp_x
vars="str=""   """:dsp_x
vars="str=""⇶""":dsp_x
vars="str=""a""":dsp_x
vars="str=""as""":dsp_x
vars="str=""asd""":dsp_x
vars="str=""asdf""":dsp_x
vars="str=chrW(8694)":dsp_x
vars="str=chr(43)":dsp_x
vars="str=Unescape(""%43%65"")":dsp_x
vars="str=Unescape(""%43%u2265"")":dsp_x
</script>
HTML Web Page In-line Output:
Results on Microsoft Windows 8.1 Pro x64, Microsoft-IIS/8.5, VBScript Version 5.8 of page /internet/users/sideblog/default.asp
varsstr, TypeNameLen(str), TypeNameLenB(str), TypeNamestr=Null[], Null[], Null[], Nullstr=Empty[], Empty[0], Long[0], Longstr=""[], String[0], Long[0], Longstr=" "[ ], String[1], Long[2], Longstr=a[3/31/2018], Date[9], Long[18], Longstr="  "[  ], String[2], Long[4], Longstr="   "[   ], String[3], Long[6], Longstr="⇶"[⇶], String[1], Long[2], Longstr="a"[a], String[1], Long[2], Longstr="as"[as], String[2], Long[4], Longstr="asd"[asd], String[3], Long[6], Longstr="asdf"[asdf], String[4], Long[8], Longstr=chrW(8694)[⇶], String[1], Long[2], Longstr=chr(43)[+], String[1], Long[2], Longstr=Unescape("%43%65")[Ce], String[2], Long[4], Longstr=Unescape("%43%u2265")[C≥], String[2], Long[4], Long

Sources

Sideway BICK Blog

10/03


Copyright © 2000-2020 Sideway . All rights reserved Disclaimerslast modified on 26 January 2013