Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Icon (programming language)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Strings=== In Icon, strings are lists of characters. As a list, they are generators and can thus be iterated over using the bang syntax: <syntaxhighlight lang="icon"> every write(!"Hello, world!") </syntaxhighlight> Will print out each character of the string on a separate line. Substrings can be extracted from a string by using a range specification within brackets. A range specification can return a point to a single character, or a [[array slicing|slice]] of the string. Strings can be indexed from either the right or the left. Positions within a string are defined to be '''between''' the characters <sub>1</sub>A<sub>2</sub>B<sub>3</sub>C<sub>4</sub> and can be specified from the right <sub>β3</sub>A<sub>β2</sub>B<sub>β1</sub>C<sub>0</sub> For example, <syntaxhighlight lang="icon"> "Wikipedia"[1] ==> "W" "Wikipedia"[3] ==> "k" "Wikipedia"[0] ==> "a" "Wikipedia"[1:3] ==> "Wi" "Wikipedia"[-2:0] ==> "ia" "Wikipedia"[2+:3] ==> "iki" </syntaxhighlight> Where the last example shows using a length instead of an ending position The subscripting specification can be used as a [[value (computer science)#lrvalue|lvalue]] within an expression. This can be used to insert strings into another string or delete parts of a string. For example: <syntaxhighlight lang="icon"> s := "abc" s[2] := "123" s now has a value of "a123c" s := "abcdefg" s[3:5] := "ABCD" s now has a value of "abABCDefg" s := "abcdefg" s[3:5] := "" s now has a value of "abefg" </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)