slice


Description:

public string slice (long start, long end)

Extracts the text from one string and returns a new string.

If start or end is negative, string.slice uses it as a character index from the end of the string.

Example: Extract text from one string:

static int main (string[] args) {
string wisdom = "水は方円の器に従い、人は善悪の友による。";
int start = wisdom.index_of_nth_char (5); // 器
int end = wisdom.index_of_nth_char (10); // 人

// Output: ``器に従い、``
string res = wisdom.slice (start, end);
print ("%s\n", res);
return 0;
}

valac --pkg glib-2.0 string.slice.vala

Parameters:

start

the zero-based byte-index at which to begin extraction.

end

the zero-based byte-index at which to end extraction.

Returns:

a newly-allocated string holding the result.