Command Reference : String and Date Function Reference
Remove leading and trailing commas surrounding string.
Syntax: @stripcommas(str)
str: string
Return: string
Returns the contents of the string str with leading and trailing commas (ignoring whitespace) stripped.
Leading and trailing commas are always removed, even if unpaired. All whitespace characters up to the leading comma and whitespace characters after the trailing comma are also removed.
Define the string object
string s1 = " , lettuce, tomato, onion, "
so that S1 contains the string “ , lettuce, tomato, onion, ”. Note the presence of the whitespace before the leading, and after the trailing comma.
Then the commands
string sc1 = @stripcommas(" , lettuce, tomato, onion, ")
string sc2 = @stripcommas(s1)
create SC1 and SC2 which contain the string “ lettuce, tomato, onion”. Note that the resulting string retains the space (“ ”) after the initial comma, but not the space after the last comma in S1.
If ALPHA1 is an alpha series, the command
alpha a1 = @stripcommas(alpha1)
fills A1 with strip-comma values of ALPHA1 for each observation in the workfile sample.
If AVEC1 is an svector, the commands
svector as1 = @stripcommas(avec1)
svector as2 = @stripcommas(avec1.@rows(@fill(1, 3, 5))
create svectors AS1 and AS2, where AS1 contains double-quoted values of AVEC1, and AS2 contains double-quoted values of the rows 1, 3, and 5 of AVEC1.
See also @stripparens and @stripquotes.