2017-09-17 75 views
0

我想用装饰来删除空行:可以反弹修剪删除空白行而不删除CRLF?

line 1 

line 2 

得到

line1 
line2 

但使用

trim/lines 

并同时删除CRLF。那么是否有另一种使用trim的方法?

+0

您提到的CRLF不清楚,因为您还使用“空白行”表达式。 Rebol不使用CRLF序列来标记新行,而是使用LF字符。那么你的意思是LF,还是你的意思是一个Rebol字符串,它包含CRLF序列(ASCII 13后跟ASCII 10)? – DocKimbel

回答

3
replace/all {Line1^/^/Line2} {^/^/} {^/} 
4

你可以使用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 
    ] 
] 
1

没有办法只是装饰,但这里有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 
]