武兵 7933 字 5個月前

ICON語言

(4 / 7)
⚡ 登入後報錯可獲 3天VIP 免廣告——立即登入

e.Whentheloopterminates,controlflowsofftheendoftheprocedurewithoutproducinganothervalue.

3.StringScanning

Forcomplicatedoperations,thebookkeepinginvolvedinkeepingtrackofpositionsinstringsbecomesburdensomeanderrorprone.Iconhasastringscanningfacilitythatismanagespositionsautomatically.Attentionisfocusedonacurrentpositioninastringasitisexaminedbyasequenceofoperations.

Thestringscanningoperationhastheform

s?expr

wheresisthesubjectstringtobeexaminedandexprisanexpressionthatperformstheexamination.Apositioninthesubject,whichstartsat1,isthefocusofexamination.

Matchingfunctionschangethisposition.Onematchingfunction,move(i),movesthepositionbyiandproducesthesubstringofthesubjectbetweenthepreviousandnewpositions.Ifthepositioncannotbemovedbythespecifiedamount(becausethesubjectisnotlongenough),move(i)fails.Asimpleexampleis

line?whilewrite(move(2))

whichwritessuccessivetwo-charactersubstringsofline,stoppingwhentherearenomorecharacters.

Anothermatchingfunctionistab(i),whichsetsthepositioninthesubjecttoiandalsoreturnsthesubstringofthesubjectbetweenthepreviousandnewpositions.Forexample,

line?iftab(10)thenwrite(tab(0))

firstsetsthepositioninthesubjectto10andthentotheendofthesubject,writingtheremainingcharacters.Notethatnovalueiswrittenifthesubjectisnotlongenough.

Stringanalysisfunctionssuchasfind()canbeusedinstringscanning.Inthiscontext,thestringthattheyoperateonisnotspecifiedandistakentobethesubject.Forexample,

line?whilewrite(tab(find(\"or\")))

domove(2)

writesallthesubstringsoflinepriortooccurrencesof\"or\".Notethatfind()producesaposition,whichisthenusedbytab()tochangethepositionandproducethedesiredsubstring.Themove(2)skipsthe\"or\"thatisfound.

Anotherexampleoftheuseofstringanalysisfunctionsinscanningis

line?whiletab(upto(&letters))do

𝐰𝐭.𝐩𝐨𝐨名域的們我住記請

)))srettel&(ynam(bat(etirw

.enilnisdrowehtllasetirwhcihw

.noisserpxegninnacsehtniruccoyamnoisserpxeyna,evobaselpmaxeehtnidetartsullisA

erutcurtS.4

.msinahcempukoolevitaicossanaedivorpselbaT.gniredrodeilpmionhtiwseulavyrartibrafosnoitcellocerasteS.snoitcnufeueuqdnakcatsybdnanoitisopybhtobdesseccaebnactahtserutcurtsraenilerastsiL.sdohtemsseccadnasnoitazinagrotnereffidhtiwserutcurtsfosdniklarevesstroppusnocI

stsiL1.4

isolcneybdetaercerastsiL.sepytyrartibrafoseulavfosecneuqeseranocInistsil,sretcarahcfosecneuqeserasgnirtselihW


✅ 付款功能已修復,現在可以正常購買了 — 支援信用卡 · Apple Pay · Google Pay · WebATM · ATM 轉帳
😤 廣告總在最入戲的時候跳出來?
月付 $5 USD,升級 VIP 後全站所有頁面廣告立即全關——
不是只有這本書,是整個 oop.tw 每一頁、每一章,從此一路讀到底不被打斷。 $5 USD ≈ 一杯珍奶的錢,換一整個月零廣告清爽閱讀 · 隨時可取消
✅ 全站廣告全關 ✅ 工口專區全本解鎖 ✅ 月卡 $5 USD · 季卡 $13 USD · 年卡 $45 USD
⭐ 登入 / 免費註冊後升級
加我 LINE 好友,分享好書不錯過
第一時間獲得新書推薦、書單更新通知
立即加入
上一頁 書頁/目錄
/ 7 頁
下一頁
為本書評分(每位讀者可評一次,提交後無法修改)
發表評論
以 匿名讀者 身份發表
讀者評論