This wiki is out of date, use the continuation of this wiki instead

Substr

From FenixWiki

Jump to: navigation, search


Contents

[edit] Definition

INT substr ( <STRING str> , <INT startposition> , [<INT characters>] )

Returns a subsection of a certain string.

[edit] Parameters

STRING str - The string of which a subsection will be returned.
INT startposition - The position of the first character to be in the subsection.
[INT characters] - The number of characters the subsection will hold. Negative values are special; see Notes.

[edit] Returns

STRING : The subsection.

[edit] Notes

Before Fenix 0.92, if the number of characters is specified as 0, it is interpreted the same as if the number of characters were not specified, meaning the returned string will be all characters from startposition. Because of this, code like implementation of backspace functionality should be done a little different:

if(len(str)>1)
    str = substr(str,0,len(str)-1);
else
    str = "";
end

Used in code: len()

If the number of characters is a negative value, the following applies: the start of the subsection will be startposition; the end of the subsection will be the length of the string minus the absolute value of characters.

[edit] Example

Private                             
    String str = "This is my string.";
Begin

    // No specified number of characters
    say( substr(str,2)     + "<" ); // "is is my string."
    say( substr(str,-7)    + "<" ); // "string."

    // Specified number of characters
    say( substr(str,5,2)   + "<" ); // "is"

    // Number of characters greater than length of string
    say( substr(str,2,50)  + "<" ); // "is my string."
    say( substr(str,-7,50) + "<" ); // "is"

    // Negative number of characters
    say( substr(str,5,-5)  + "<" ); // "is my st"

    // Special case
    say( substr(str,0,0)   + "<" ); // "", but pre 0.92: "This is my string."

    Repeat
        frame;
    Until(key(_ESC))

End

Used in example: say(), key()


Strings Functions
Asc() • Atof() • Atoi() • Chr() • Find() • Ftoa() • Itoa() • Lcase() • Len() • Strrev() • Substr() • Ucase() •
Personal tools