我知道如何用空格分隔字符串序列:
(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
答案 0 :(得分:2)
请改为尝试:
(split-sequence-if (lambda (s) (equal s " ")) "1 2 3 4")
或者这个:
(split-sequence #\Space "1 2 3 4" :remove-empty-subseqs t)
答案 1 :(得分:1)
(ql:quickload "cl-ppcre")
(cl-ppcre:split "\\s\\s" "One Two Three Four Five")
("One" "Two Three" "Four" " Five")
显然,无论你从其他使用正则表达式的语言中学到什么都适用。
答案 2 :(得分:0)
这可能是因为你的字符串没有用空格分隔
(split-sequence " " "1 2 3 4")
试
(split-sequence " " "1 2 3 4")