help mata invtokens()
-------------------------------------------------------------------------------
Title
[M-5] invtokens() -- Concatenate string rowvector into string scalar
Syntax
string scalar invtokens(string rowvector s)
string scalar invtokens(string rowvector s, string scalar c)
Description
invtokens(s) returns the elements of s, concatenated into a string scalar
with the elements separated by spaces. invtokens(s) is equivalent to
invtokens(s, " ").
invtokens(s, c) returns the elements of s, concatenated into a string
scalar with the elements separated by c.
Remarks
invtokens(s) is the inverse of tokens() (see [M-5] tokens()); invtokens()
returns the string obtained by concatenating the elements of s into a
space-separated list.
invtokens(s, c) places c between the elements of s even when the elements
of s are equal to "". For instance,
: s = ("alpha", "", "gamma", "")
: invtokens(s, ";")
alpha;;gamma;
To remove separators between empty elements, use select() (see [M-5]
select()) to remove the empty elements from s beforehand:
: s2 = select(s, strlen(s):>0)
: s2
1 2
+-----------------+
1 | alpha gamma |
+-----------------+
: invtokens(s2, ";")
alpha;gamma
Conformability
invtokens(s, c):
s: 1 x p
c: 1 x 1 (optional)
result: 1 x 1
Diagnostics
If s is 1 x 0, invtokens(s,c) returns "".
Source code
invtokens.mata
Also see
Manual: [M-5] invtokens()
Help: [M-5] tokens(); [M-4] string