String

Public Instance Methods

ext(newext='')click to toggle source

Replace the file extension with newext. If there is no
extension on the string, append the new extension to the end. If the new
extension is not given, or is the empty string, remove any existing
extension.

The %d specifier can also have a numeric prefix (e.g. ‘%2d’). If the number
is positive, only return (up to) n directories in the path,
starting from the left hand side. If n is negative, return
(up to) |n| directories from the right hand side of the path.

Also the %d, %p, %f, %n, %x, and %X operators can take a
pattern/replacement argument to perform simple string substitutions on a
particular part of the path. The pattern and replacement are separated by
a comma and are enclosed by curly braces. The replacement spec comes after
the % character but before the operator letter. (e.g. “%{old,new}d”).
Multiple replacement specs should be separated by semi-colons (e.g.
“%{old,new;src,bin}d”).

Regular expressions may be used for the pattern, and back refs may be used
in the replacement text. Curly braces, commas and semi-colons are excluded
from both the pattern and replacement text (let’s keep parsing reasonable).

For example:

"src/org/onestepback/proj/A.java".pathmap("%{^src,bin}X.class")

returns:

"bin/org/onestepback/proj/A.class"

If the replacement text is ‘*’, then a block may be provided to perform
some arbitrary calculation for the replacement.