Skip to content

Text functions

The luego.text package contains utility functions to work with text data.

luego.text

charAt

charAt(t: Text, i: Integer) => Char

Returns the character at the specified index i in a text t

charAtOpt

charAtOpt(t: Text, i: Integer) => Option[Char]

Returns the character at the specified index i in a text t, wrapped in an option

compareTo

compareTo(t1: Text, t2: Text) => Integer

Compares the two input texts lexicographically

compareToIgnoreCase

compareToIgnoreCase(t1: Text, t2: Text) => Integer

Compares the two input texts lexicographically, ignoring case differences

containsSubstring

containsSubstring(t: Text, subtext: Text) => Boolean

Returns true if and only if the first text contains the second one

DateAsTextEn

DateAsTextEn(d: Date) => Text

Generate a text for the input date in the current EN locale

DateAsTextFr

DateAsTextFr(d: Date) => Text

Generate a text for the input date in the current FR locale

endsWith

endsWith(t: Text, suffix: Text) => Boolean

Tests if this text ends with the specified suffix

extractWords

extractWords(t: Text) => List[Text]

Split a text into a sequence of words

FormatFloatNumber

FormatFloatNumber(d: Number) => Text

Format numeric value d to text using continental Europe format

FormatFloatNumber_US

FormatFloatNumber_US(d: Number) => Text

Format numeric value d to text using US format

FormatNumber

FormatNumber(d: Number, f: Text) => Text

Format numeric value d to text using format f

indexOf

indexOf(t: Text, substring: Text) => Integer

Returns the index within this string s of the first occurrence of the specified substring

isEmpty

isEmpty(t: Text) => Boolean

Tests whether the input text t is empty. For example: isEmpty('') returns true, isEmpty('Abc') returns false

isLower

isLower(t: Text) => Boolean

Tells whether the input text contains only lowercase letters. For example: isLower('abc') returns true, isLower('Abc') returns false

isUpper

isUpper(t: Text) => Boolean

Tells whether the input text t contains only uppercase letters. For example: isUpper('ABC') returns true, isUpper('Abc') returns false

isValidEmail

isValidEmail(t: Text) => Boolean

Tells whether the input text is a valid email address

lastChar

lastChar(t: Text) => Char

Returns the last character of a text t

lastCharOpt

lastCharOpt(t: Text) => Option[Char]

Returns the last character of a text t wrapped in an option

lastIndexOf

lastIndexOf(t: Text, substring: Text) => Integer

Returns the index within this string of the last occurrence of the specified substring

length

length(t: Text) => Integer

Returns the length of the input text t. For example: length('hello') returns 5, length('') returns 0

lower

lower(t: Text) => Text

Returns a new Text with all of the characters converted to lower case. For instance, lower('HELLO') return 'hello'

matches

matches(t: Text, regex: Text) => Boolean

Tells whether or not this text matches the given regular expression

mkString

mkString(li: List[Text], s: Text) => Text

Returns a text obtained by concatenating the list of input texts with a separator s

onlyDigits

onlyDigits(t: Text) => Boolean

Tests whether the input text t only contains digits. For example: onlyDigits('1234') returns true, onlyDigits('1234A') returns false

print

print(t: Text) => Unit

Prints out the input text t to the default output

println

println(t: Text) => Unit

Prints out the input text to the default output, followed by a newline

repeat

repeat(t: Text, n: Integer) => Text

Returns the input Text t concatenated n times.

replace

replace(t: Text, f: Text, r: Text) => Text

Replaces each substring of t that matches the literal target sequence f with the specified literal replacement sequence r

replaceAll

replaceAll(t: Text, f: Text, r: Text) => Text

Replaces each substring of this string that matches the given regex with the literal replacement.

reverse

reverse(t: Text) => Text

Returns a new Text with characters in reverse order. For instance, reverse('hello') return 'olleh'

split

split(t: Text, s: Text) => List[Text]

Split a text t using a separator s

startsWith

startsWith(t: Text, prefix: Text) => Boolean

Tests if this text starts with the specified prefix

str

str(v: Any) => Text

Converts the input into a text

substring

substring(t: Text, i1: Integer, i2: Integer) => Text

Returns substring of t between the specified indexes

substringOpt

substringOpt(t: Text, i1: Integer, i2: Integer) => Option[Text]

Returns substring of s between the specified indexes, wrapped in an option

TimeFromDTAsText

TimeFromDTAsText(dt: DateTime) => Text

Generate a text for the time extracted from the input dateTime

toInt

toInt(t: Text) => Integer

Converts the input text t to an Integer. This can fail if t does not have an Integer format.

toIntOption

toIntOption(t: Text) => Option[Integer]

Tries to parse the input text tas an Integer option. This is the safe version of toInt

toNumber

toNumber(t: Text) => Number

Converts the input text t to an Number. This can fail if t does not have an Number format.

toNumberOption

toNumberOption(t: Text) => Option[Number]

Tries to parse the input text t as a Number option. This is the safe version of toNumber

trim

trim(t: Text) => Text

Returns a copy of the input Text, with leading and trailing whitespace omitted

upper

upper(t: Text) => Text

Returns a new Text with all of the characters converted to upper case. For instance, upper('hello') return 'HELLO'

upperFirstLetter

upperFirstLetter(t: Text) => Text

Returns a new Text with the first character converted to upper case. For instance, upperFirstLetter('hello') return 'Hello'