30.3 SubString

SubString( string, from, to )

SubString returns the substring of the string string that begins at position from and continues to position to. The characters at these two positions are included. Indexing is done with origin 1, i.e., the first character is at position 1. from and to must be integers and are both silently forced into the range 1..LengthString(string) (see LengthString). If to is less than from the substring is empty.

    gap> SubString( "Hello world.\n", 1, 5 );
    "Hello"
    gap> SubString( "Hello world.\n", 5, 1 );
    "" 

Because strings are now lists, substrings can also be extracted with string{[from..to]} (see List Elements). SubString forces from and to into the range 1..Length(string), which the above does not, but apart from that SubString is obsolete.

Previous Up Top Next
Index

GAP 3.4.4
April 1997