我想解析字符串以找到在(character, n)
集合中找到的前N個重複字符。 (例如,對於"ozzllluu"
和集合(「u」=> 2),(「d」=> 2),(「l」=> 3)和(「r」=> 3)...我想找到「lll」,因爲它是3個字符,發生在兩個「u」之前。解析字符串以查找第一個重複字符 - 函數與prodecural編碼樣式
程序風格的解決方案:
Rebol []
seq-set: [#"u" 2 #"d" 2 #"l" 3 #"r" 3]
str: "ozzllluu"
lastchar: ""
cnt: 1
seq-char: ""
foreach char str [
either char = lastchar [
cnt: cnt + 1
if (select seq-set char) = cnt [
seq-char: char
break
]
][
cnt: 1
]
lastchar: char
]
either seq-char = "" [
print "no seq-char"
][
print join "seq-char " seq-char
]
我會怎麼做使用parse
規則同樣的事情?
簡而言之:
parse
字符串中(字符,N)發現前n複製的字符集- 「功能」 的現行程序代碼
- 狗食到雷博爾/紅!
提示:對問題或答案中的「幽默」非常小心。你的方法簡直讓我困惑。你希望別人花時間幫助你。沒有必要對此有趣。既不問,也不在回答時。是的,有時候這很好,但特別是在「只寫」對話中,「好幽默」很難**。 – GhostCat
@GhostCat \t \t https://en.wikipedia.org/wiki/Eating_your_own_dog_food - \t \t \t搜索 「微軟」 – OneArb