LEN returns the number of characters in a string.
Syntax:RetVal = LEN(MainStr AS STRING) Return Value:
Parameters:
|
DIM a$ DIM i% FOR i% = 65 TO 65+25 a$ = a$ & CHR$(i%) NEXT i% = LEN(a$) ? "The length of a$ = " , i%
The length of a$ = 26
MEMSIZE is an alias to the CRT function _msize. MEMSIZE is a case insensitive keyword that takes a dynamically dimensioned variable, that is, memory allocated using malloc, calloc, or realloc and returns its current memory allocation.
Syntax:RetVal = MEMSIZE(MainStr AS STRING) Return Value:
Parameters:
|
See NEXTLINELEN below for an example of the usage of MEMSIZE.
LONGESTLINE returns the length of the longest line in any text file, where each line of text is terminated with a CRLF.
Syntax:RetStr = LONGESTLINE(FileName AS STRING) Return Value:
Parameters:
|
The sample below will display the line(s) that equal the the length of the longest line in the file.
DIM LL, A$ LL = LONGESTLINE("bc.bas") OPEN "Bc.bas" FOR INPUT AS 1 WHILE NOT EOF(1) LINE INPUT 1, A$ IF LEN(A$) = LL THEN PRINT A$ WEND CLOSE
SecondVar$ = "Line" + STR$(LocalVars[s].VarLine) + " in Module: " + LocalVars[s].VarModule$ + " : " + LocalName$ + LocalVars[s].VarDim$ + " as " + GetVarTypeName$(LocalVars[s].VarType) + SPC$ + TypeDefs[LocalVars[s].VarDef].VarName$
NEXTLINELEN returns the length of the next line to be read from a currently open text file, where each line of text is terminated with a CRLF. This provides an opportunity to REDIM a receiving string variable before executing a LINE INPUT function, helping to prevent buffer overruns.
Syntax:RetVal = NEXTLINELEN(FileHandle AS FILE) Return Value:
Parameters:
|
FUNCTION Fetchline (FP AS FILE, BYREF MyBuf$) AS UINT DIM LineLen AS UINT '========================== Query the next line length. LineLen = NEXTLINELEN(FP) '<- Our new file function '========================== REDIM MyBuf$ only when needed. IF MEMSIZE(MyBuf$) < LineLen THEN REDIM MyBuf$ * LineLen LINE INPUT FP, MyBuf$ FUNCTION = LineLen END FUNCTION