Icon (programming Language) - Strings

Strings

In keeping with its script-like functionality, Icon adds a number of features to make working with strings easier. Most notable among these is the scanning system, which repeatedly calls functions on a string:

s ? write(find("the"))

is a short form of the examples shown earlier. In this case the subject of the find function is placed outside the parameters in front of the question-mark. Icon functions are deliberately (as opposed to automatically) written to identify the subject in parameter lists and allow them to be pulled out in this fashion.

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 slice of the string. Strings can be indexed from either the right or the left. It is important to note that positions within a string are between the characters 1A2B3C4 and can be specified from the right -3A-2B-1C0

For example

"Wikipedia" ==> "W" "Wikipedia" ==> "k" "Wikipedia" ==> "a" "Wikipedia" ==> "Wi" "Wikipedia" ==> "ia" "Wikipedia" ==> "iki"

Where the last example shows using a length instead of an ending position

The subscripting specification can be used as a Lvalue within an expression. This can be used to insert strings into another string or delete parts of a string. For example,

s := "abc" s := "123" s now has a value of "a123c" s := "abcdefg" s := "ABCD" s now has a value of "abABCDefg" s := "abcdefg" s := "" s now has a value of "abefg"

Read more about this topic:  Icon (programming Language)

Famous quotes containing the word strings:

    A culture may be conceived as a network of beliefs and purposes in which any string in the net pulls and is pulled by the others, thus perpetually changing the configuration of the whole. If the cultural element called morals takes on a new shape, we must ask what other strings have pulled it out of line. It cannot be one solitary string, nor even the strings nearby, for the network is three-dimensional at least.
    Jacques Barzun (b. 1907)

    How have you left the ancient love
    That bards of old enjoyed in you!
    The languid strings do scarcely move!
    The sound is forced, the notes are few!
    William Blake (1757–1827)

    Love’s the only thing I’ve thought of or read about since I was knee-high. That’s what I always dreamed of, of meeting somebody and falling in love. And when that remarkable thing happened, I was going to recite poetry to her for hours about how her heart’s an angel’s wing and her hair the strings of a heavenly harp. Instead I got drunk and hollered at her and called her a harpy.
    Ben Hecht (1893–1964)