@Word (JavaScript)

Returns a word from a string.

Defined in

@Functions (JavaScript)

Syntax

@Word(value:string, separator:string, n:int) : string
Parameter Description
value The string or string list to be checked.
separator A series of characters treated as separators. Characters between separators are treated as words.
n The number of the word where 1 is the first word.
Return value Description
string Word number n in value. Returns the first word if n is 0 or negative. Returns the empty string if n exceeds the number of words in the string.

Usage

If value is an array of strings, each element is processed against parameters 2 and 3, and the return value is an array with corresponding elements.

Examples

This example extracts words from a string where words are delimited by a comma and a space.
function p(stuff) {
	print("<<<" + stuff + ">>>"); 
 }

var cities = "Paris, Berlin, Moscow, London";

var n = 1;
var city = @Word(cities, ", ", n);
while(city != "") {
	p(n + " " + city);
	n++;
	city = @Word(cities, ", ", n);
}/*
<<<1 Paris>>>
<<<2 Berlin>>>
<<<3 Moscow>>>
<<<4 London>>>
*/