lines()
Return the number of lines in a string.
Syntax
lines(text)
Parameter
Parameter | Definition |
---|---|
text | text to be counted for number of lines (that is, new-line characters) The text can be the name of a text file, a text string enclosed in double quotation marks, or one or more PSL commands that produce text as output. |
Description
The lines() function returns the number of new-line characters in text. You can also use the lines() function for returning the length of a list, because the items in a list are delimited by new lines.
Example
In the following example, the lines() function call returns the number of lines in a character string and in a character list:
string = "Jack and Jill\nwent up the hill";
print ("Lines in string: ",lines(string),"\n");
list = [5,"lines","in","this","list"];
print("Lines in list: ",lines(list),"\n");
print ("Lines in string: ",lines(string),"\n");
list = [5,"lines","in","this","list"];
print("Lines in list: ",lines(list),"\n");