Title = 'A Tale of two Cities, Charles j.Dickens';
Word1 =scan(title, 1 , ',');
Word2 =scan(title, 2 , ',');
Word3 =scan(title, 3 , ',');
Word4 =scan(title, 1 , ' ,');/*以下3个例子均有空格*/
Word5 =scan(title, 2 , ' ,');
Word6 =scan(title, 3 , ' ,');
run;
复制代码
分隔符号‘,’ ( 前面无空格),将字符串title分割成2个单元, 第1个就是 A Tale of two Cities ,第2个就是Charles j.Dickens,第3个不存在,因此为空。
分隔符号‘ ,’ 前面有空格 , 为非常规分隔符,默认为空格,因此第1个就是A ,第2个就是Tale ,第3个就是of。
常见的分割符与PC系统有关:
If you use the SCAN function with only two arguments, then the default delimiters depend on whether your computer uses ASCII or EBCDIC characters.
If your computer uses ASCII characters, then the default delimiters are as follows:
blank ! $ % & ( ) * + , - . / ; < ^ |
In ASCII environments that do not contain the ^ character, the SCAN function uses the ~ character instead.
If your computer uses EBCDIC characters, then the default delimiters are as follows:
blank ! $ % & ( ) * + , - . / ; < ¬ | ¢
If you use the modifier argument without specifying any characters as delimiters, then the only delimiters that will be used are delimiters that are defined by the modifier argument. In this case, the lists of default delimiters for ASCII and EBCDIC environments are not used. In other words, modifiers add to the list of delimiters that are explicitly specified by the charlist argument. Modifiers do not add to the list of default modifiers.