help for charlist

List characters present in string variable

charlist strvar [if exp] [in range]


charlist displays a sorted list of the distinct characters present in values of string variable strvar.


charlist may, for example, reveal the presence of problematic characters in a string variable which "should be" numeric. It leaves behind a terse character list in r(chars); a space-separated character list in r(sepchars); and a space-separated numlist of ASCII codes in r(ascii). Any may be used in a subsequent command. Sometimes copying and pasting all or part of the displayed output to the command window may be the most practical way to use the output, say as argument to destring, ignore().

Note in particular that many awkward characters may not print comprehensibly or visibly in your Results window. To some extent, this will depend on the font you choose. A particular pitfall is that char(32) and char(160) appear identical and may be overlooked in any case. The returned results showing ASCII codes are needed to solve many of these difficulties.


. charlist make

. charlist make if foreign

. charlist rank . return list [suppose results show instances of char(160)] . destring rank, ignore(`=char(160)')

Saved results

r(chars) compressed list of distinct characters r(sepchars) space-separated list of distinct characters r(ascii) numeric list of distinct ASCII codes (cf. char())


Daniel Egan posed a problem that led to extra comments and examples in this help file.


Nicholas J. Cox, Durham University, U.K. n.j.cox@durham.ac.uk

Also see

On-line: help for destring, functions