rgc*_*ris 9 string performance newline rebol
给定一个字符串string
,在其中计算行的最快/最有效的方法是什么?将接受任何风格的Rebol的最佳答案.我一直在假设parse [some [thru]]
组合是遍历字符串的最快方式,但后来我不确定,因此转向SO:
count-lines: func [string [string!] /local count][
parse/all string [
(count: 1) some [thru newline (count: count + 1)]
]
count
]
Run Code Online (Sandbox Code Playgroud)
要么:
count-lines: func [string [string!] /local count][
count: 0
until [
count: count + 1
not string: find/tail string newline
]
count
]
Run Code Online (Sandbox Code Playgroud)
柜台怎么样?重复效率如何?
count-lines: func [string [string!]][
repeat count length? string [
unless string: find/tail string newline [
break/return count
]
]
]
Run Code Online (Sandbox Code Playgroud)
更新:行计数采用文本编辑器原则:
空文档的行数仍为1.所以:
>> count-lines ""
== 1
>> count-lines "^/"
== 2
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
648 次 |
最近记录: |