اذا لم تجد ما تبحث عنه يمكنك استخدام كلمات أكثر دقة.
تتمثل إحدى الميزات القوية للغة Icon في فحص السلاسل. وعامل فحص السلاسل، ? يحفظ بيئة فحص السلاسل الحالية وينشئ بيئة فحص سلاسل جديدة. تتكون بيئة فحص السلاسل من متغيري كلمات أساسية، &subject و&pos. حيث يمثل &subject السلسلة التي يجري فحصها، بينما &pos يمثل المؤشر أو الموضع الحالي داخل سلسلة subject. على سبيل المثال
s := "this is a string" s ? write("subject=[",&subject,"] pos=[",&pos,"]")
ستنتج
subject=[this is a string] pos=[1] يمكن استخدام الدوال المضمنة والمعرفة من قبل المستخدم للتحرك داخل السلسلة التي يجري فحصها. والعديد من الدوال المضمنة ستكون افتراضيًا &subject و&pos (على سبيل المثال دالة find). والتعليمات التالية، على سبيل المثال، ستكتب كل "الكلمات" المحددة الفارغة في سلسلة.
s := "this is a string" s ? { # Establish string scanning environment while not pos(0) do { # Test for end of string tab(many(" ")) # Skip past any blanks word := tab(upto(" ") | 0) # the next word is up to the next blank -or- the end of the line write(word) # write the word } }
مثال أكثر تعقيدًا يوضح دمج المولدات وفحص السلاسل داخل اللغة.
procedure main() s := "Mon Dec 8" s ? write(Mdate() | "not a valid date") end # Define a matching function that returns # a string that matches a day month dayofmonth procedure Mdate() # Define some initial values static dates static days initial { days := ["Mon","Tue","Wed","Thr","Fri","Sat","Sun"] dates := ["Jan","Feb","Mar","Apr","May","Jun", "Jul","Aug","Sep","Oct","Nov","Dec"] } every suspend (retval <- tab(match(!days)) || # Match a day =" " || # Followed by a blank tab(match(!dates)) || # Followed by the month =" " || # Followed by a blank matchdigits(2) # Followed by at least 2 digits ) & (=" " | pos(0) ) & # Either a blank or the end of the string retval # And finally return the string end # Matching function that returns a string of n digits procedure matchdigits(n) suspend (v := tab(many(&digits)) & *v <= n) & v end
مصطلح expr1 & expr2 & expr3 يعطي قيمة التعبير الأخير