[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
substr(s,p)                  sub-string

    Return string formed from suffix of string s starting at position p.

substr(s,p,n)                sub-string

    Return string formed from n characters of string s starting at position
    p.

    Derive two strings, path  and filename, from DOS  path\filename string.
    Strategy:  use pattern to find filename[.ext] at end of string and  set
    to null string for path, get suffix for filename[.ext].

    pathfile == "a:\path1\subpath2\file1.ext";

        # characters excluded from filename
    exc_c = /[!\x01-\x21."\/\\\[\]:|<>+=;,]/;
        # DOS filename.ext pattern
        # filename consists of all characters not excluded from proper name
        # followed by optional extension of 1 to 3 characters
        # followed by end of string
    name_pat = /{exc_c}+(.{exc_c}{1,3})?$/;

        path = pathfile;
           # delete filename.ext at end to leave path
        sub(name_pat,"",path);
           # get suffix of path in pathfilename
        filename = substr(pathfile,1 + length(path));

    path ==>     "a:\path1\subpath2\"
    filename ==> "file1.ext";

See Also: sub
This page created by ng2html v1.05, the Norton guide to HTML conversion utility. Written by Dave Pearson