PreviousUpNext

5.5.30  Drop last N characters of a string

Drop the last character of a string:

    eval:  string::extract ("fubar", 0, THE (string::length_in_bytes "fubar" - 1));
    "fuba"

Another way:

    eval:  regex::find_first_match_to_ith_group 1 ./^(.*).$/ "fubar";
    THE "fuba"

Drop the last two characters of a string:

    eval:  string::extract ("fubar", 0, THE (string::length_in_bytes "fubar" - 2));
    "fub"

Another way:

eval:  regex::find_first_match_to_ith_group 1 ./^(.*)..$/ "fubar";
THE "fub"

Comments and suggestions to: bugs@mythryl.org

PreviousUpNext