substr

substr -- returns a substring for a given location.

Syntax

substr (string, start_char, length)

		

Arguments

string

A string.

start_char

The position number of the first character of the substring.

length

The length of the substring.

Returns

A new string which is a substring of the input string.

Description

This function returns a substring of the input string starting at the start_char position and running for length characters. The first character in the string is numbered zero. If start_char is greater than the length of the string, the function returns an empty string. If start_char is negative, it is indexed from the end of the string. If it is negative and greater than the length of the string, it is treated as zero--the beginning of the string.

If there are fewer characters than length in the string, or if length is -1, then the substring contains all characters from start_char to the end of the string.

Example

    Gamma> substr("Acme widgets",7,3);
    "dge"
    Gamma> substr("Acme widgets",9,-1);
    "ets"
    Gamma> substr("Acme widgets",-7,4);
    "widg"
    Gamma> substr("Acme widgets",-30,4);
    "Acme"
    Gamma> 
    		

See Also

strchr, strrchr, string, strstr

Copyright 1995-2002 by Cogent Real-Time Systems, Inc.