*检查城市名称是否都以一个字结尾。
gen city2 = substr(city,-3,.)
tab city2 //所有城市都是以一个字结尾,那么我只用去掉最后一个字就行。
If n1 < 0, n1 is interpreted as the distance from the end of the string; if n2 = . (missing), the remaining portion of the string is returned.
substr("abcdef",2,3) = "bcd"
substr("abcdef",-3,2) = "de"
substr("abcdef",2,.) = "bcdef"
substr("abcdef",-3,.) = "def"
substr("abcdef",2,0) = ""
substr("abcdef",15,2) = ""
gen city_1 = substr(city,1,strlen(city)-3) //截取到倒数第2个字。
strlen(s)
Description: the number of characters in ASCII s or length in bytes
strlen() is intended for use with only plain ASCII characters and for use by programmers who want to obtain the
byte-length of a string. Note that any Unicode character beyond ASCII range (code point greater than 127) takes more
than 1 byte in the UTF-8 encoding; for example, é takes 2 bytes.
For the number of characters in a Unicode string, see ustrlen().
strlen("ab") = 2
strlen("é") = 2
Domain s: strings
Range: integers > 0