小编gna*_*nat的帖子

在Rebol或Red中搜索字符串

我有兴趣搜索很多长串,尝试在rebol中破解类似sed的实用程序作为学习练习.作为一个婴儿步骤,我决定寻找一个角色:

>> STR: "abcdefghijklmopqrz"

>> pos: index? find STR "z"
== 18

>> pos
== 18
Run Code Online (Sandbox Code Playgroud)

大!我们来寻找其他东西......

>> pos: index? find STR "n"
** Script Error: index? expected series argument of type: series port
** Where: halt-view
** Near: pos: index? find STR "n"

>> pos
== 18
Run Code Online (Sandbox Code Playgroud)

什么?:-(

是的,我正在搜索的字符串中没有"n".但是解释器爆炸而不是做一些明智的事情有什么好处,例如在pos中返回一个可测试的"null"字符?

我被告知我应该这样做:

>> if found? find STR "z" [pos: index? find STR "z"]
== 18

>> if found? find STR "n" [pos: index? find STR "n"]
== none

>> pos
== …
Run Code Online (Sandbox Code Playgroud)

string rebol rebol2 red

10
推荐指数
1
解决办法
440
查看次数

标签 统计

rebol ×1

rebol2 ×1

red ×1

string ×1