rebol trim 可以在不删除 CRLF 的情况下删除空行吗?
Can rebol trim remove blank lines without removing CRLF?
我想使用 trim 删除空行:
line 1
line 2
获得
line1
line2
但使用
trim/lines
也删除了 CRLF。那么还有另一种使用 trim 的方法吗?
replace/all {Line1^/^/Line2} {^/^/} {^/}
您可以使用 PARSE
:
parse string-with-newlines [
any [
crlf remove some crlf
| newline remove some newline
| skip
]
]
虽然使用字符集可能会更快:
text: complement charset crlf
parse string-with-newlines [
any [
some text
| crlf any crlf
| newline remove any newline
]
]
仅使用 trim 不行,但这里有一个使用 removeach 的解决方案,同时还删除了前导 LF
trim-emptyline: func [
str [string!]
/local lfb4 lfnow c
] [
lfb4: true
remove-each c str [also all [lfnow: lf = c lfb4] lfb4: lfnow]
str
]
我想使用 trim 删除空行:
line 1
line 2
获得
line1
line2
但使用
trim/lines
也删除了 CRLF。那么还有另一种使用 trim 的方法吗?
replace/all {Line1^/^/Line2} {^/^/} {^/}
您可以使用 PARSE
:
parse string-with-newlines [
any [
crlf remove some crlf
| newline remove some newline
| skip
]
]
虽然使用字符集可能会更快:
text: complement charset crlf
parse string-with-newlines [
any [
some text
| crlf any crlf
| newline remove any newline
]
]
仅使用 trim 不行,但这里有一个使用 removeach 的解决方案,同时还删除了前导 LF
trim-emptyline: func [
str [string!]
/local lfb4 lfnow c
] [
lfb4: true
remove-each c str [also all [lfnow: lf = c lfb4] lfb4: lfnow]
str
]