1

我知道如何用空格分隔字符串序列:

(defun ff-cols (dir file)
  (with-open-file (ff-cols-str pathname :direction :input)
    (length (split-sequence #\Space (read-line ff-cols-str nil 'eof)))))

但是如何用双空格分隔序列?平面文件通常具有由双空格分隔的列。

(split-sequence "  " "1  2  3  4")

返回

("1  2  3  4") ;
10

还,

(split-sequence #\Space "1  2  3  4")

返回

("1" "" "2" "" "3" "" "4") ;
10
4

3 回答 3

2

试试这个:

(split-sequence-if (lambda (s) (equal s "  ")) "1  2  3  4")

或这个:

(split-sequence #\Space "1  2  3  4" :remove-empty-subseqs t)
于 2012-11-30T11:42:52.427 回答
1
(ql:quickload "cl-ppcre")
(cl-ppcre:split "\\s\\s" "One  Two Three  Four   Five")
("One" "Two Three" "Four" " Five")

显然,您可以从其他也使用正则表达式的语言中学到的任何东西都适用。

于 2012-11-30T12:03:06.957 回答
0

这可能是因为您的字符串没有用双空格分隔

(split-sequence "  " "1 2 3 4")

尝试

(split-sequence "  " "1  2  3  4")
于 2012-11-30T10:36:39.540 回答