2470 High Voltage SourceMeter Instrument Reference Manual
Section 13: Introduction to TSP commands
2470-901-01 Rev. A /
May
2019
13-29
String library functions
Function
Description
string.byte(
s
)
string.byte(
s
,
i
)
string.byte(
s
,
i
,
j
)
Returns the internal numeric codes of the characters
s
[
i
],
s
[
i
+1], ···,
s
[
j
]
. The default value for
i
is
1
; the default
value for
j
is
i
.
string.char(···)
Receives zero or more integers separated by commas. Returns a
string with length equal to the number of arguments, in which each
character has the internal numeric code equal to its corresponding
argument.
string.format(
formatstring
, ...)
Returns a formatted version of its variable number of arguments
following the description given in its first argument, which must be
a string. The format string follows the same rules as the
printf
family of standard C functions. The only differences are that the
modifiers
*
,
l
,
L
,
n
,
p
, and
h
are not supported and there is an
extra option,
q
. The
q
option formats a string in a form suitable to
be safely read back by the Lua interpreter; the string is written
between double quotes, and all double quotes, newlines,
embedded zeros, and backslashes in the string are correctly
escaped when written.
For example, the call:
string.format('%q', 'a string with "quotes" and \n
new line')
will produce the string:
"a string with \"quotes\" and \
new line"
The options
c
,
d
,
E
,
e
,
f
,
g
,
G
,
i
,
o
,
u
,
X
, and
x
all expect a number
as argument.
q
and
s
expect a string. This function does not
accept string values containing embedded zeros, except as
arguments to the
q
option.
string.len(
s
)
Receives a string and returns its length. The empty string
""
has
length
0
. Embedded zeros are counted, so
"a\000bc\000"
has
length
5
.
string.lower(
s
)
Receives a string and returns a copy of this string with all
uppercase letters changed to lowercase. All other characters are
left unchanged.
string.rep(
s
,
n
)
Returns a string that is the concatenation of
n
copies of the
string
s
.
string.sub(
s
,
i
)
string.sub(
s
,
i
,
j
)
Returns the substring of
s
that starts at
i
and continues until
j
;
i
and
j
can be negative. If
j
is absent, it is assumed to be equal
to
-1
(which is the same as the string length). In particular, the call
string.sub(
s
, 1,
j
)
returns a prefix of
s
with length
j
, and
string.sub(
s
, -
i
)
returns a suffix of
s
with length
i
.
string.upper(
s
)
Receives a string and returns a copy of this string with all
lowercase letters changed to uppercase. All other characters are
left unchanged.