String length: Difference between revisions

Content added Content deleted
Line 989: Line 989:
Previously, character data would be stored in arithmetic variables, using format codes such as <code>A1</code> to store one character per variable, which might be an integer or a floating-point variable of much larger size. Format <code>A2</code> would store two such characters, and so on. Code A1 would give ease of manipulation, while A8 (say for a REAL*8 variable) would save space. Numerical values would be strange, and word sizes may not be a multiple of eight bits nor character encodements require eight bits, especially on a decimal computer.
Previously, character data would be stored in arithmetic variables, using format codes such as <code>A1</code> to store one character per variable, which might be an integer or a floating-point variable of much larger size. Format <code>A2</code> would store two such characters, and so on. Code A1 would give ease of manipulation, while A8 (say for a REAL*8 variable) would save space. Numerical values would be strange, and word sizes may not be a multiple of eight bits nor character encodements require eight bits, especially on a decimal computer.


An intrinsic function LEN(text) reports the number of characters in the variable, and since these days, everyone uses computers with eight-bit characters, the byte and character counts are the same. There is no facility for fancy Unicode schemes, other than by writing suitable routines. In that regard, plotting packages often supply a special function that returns the length of a text string, ''as it would appear on the plot, in plotting units'', especially useful when the plotter's rendition of text employs a proportionally-spaced typeface and interprets superscripts and subscripts and so forth, so that the programmer can prepare code to juggle with the layout. This is of course not in any standard.
An intrinsic function LEN(text) reports the number of characters in the variable (with no consideration of any storage needed anywhere to hold the length), while SIZE(array) reports the number of elements in an array and SIZEOF(''x'') may be available to report the number of bytes of storage of ''x''. Since these days, everyone uses computers with eight-bit characters, the result from LEN will be equivalent to both a byte and a character count.

There is no facility for fancy Unicode schemes, other than by writing suitable routines. In that regard, plotting packages often supply a special function that returns the length of a text string, ''as it would appear on the plot, in plotting units'', especially useful when the plotter's rendition of text employs a proportionally-spaced typeface and interprets superscripts and subscripts and so forth, so that the programmer can prepare code to juggle with the layout. This is of course not in any standard.


===Byte Length===
===Byte Length===