String Functions¶
- fn.index : Return the i’th item of an iterable, such as a list or string.
- fn.mask : Return a mask of (length + modifier) instances of char.
- fn.length : Return the length of a string.
- fn.split : Split a string by delimiter, returning a list.
- fn.join : Join a string by delimiter. If no delimiter is provided, the list is returned as a single string.
- fn.title : Return a string in title case.
- fn.upper : Return an uppercase version of the input string.
- fn.lower : Return a lower case version of the input string.
- fn.contains : Return true or false if string is contained in another.
- fn.sub_string : Return the substring of a string from a start to an end position.
- fn.containsIgnoreCase : Return true or false if string is contained in upper- or lower case.
- fn.containsStartsWith : Return true or false if source string is the start of target string.
- fn.containsStartOf : Return true or false if start of source string is target string.
- fn.isexactly : Return true or false if source string is exactly the same as target string.
- fn.replace : Replace target substring for source substring in source string.
- fn.validate_name : Return true or false if the string as well as its stripped content (default white space removed) exists, i.e. is then more than 0 characters.
Examples:
Example | Output |
---|---|
{{ fn.index 'foo bar baz', 5 }}
|
'b'
|
{{ fn.mask X, 2, 3 }}
|
XXXXXX
|
{{ fn.length This is a valid string }}
|
22
|
{# fn.split foo:bar:baz,: #}
|
['foo', 'bar', 'baz']
|
{{ fn.join 1234, : }}
{{ fn.join 1234 }}
|
1:2:3:4
1234
|
{{ fn.title 'foo bar baz' }}
|
'Foo Bar Baz'
|
{{ fn.upper somevalue }}
|
SOMEVALUE
|
Example | Output |
---|---|
{{ fn.lower SOMEVALUE }}
|
somevalue
|
{{ fn.contains needle, haystack }}
{{ fn.contains hay, haystack }}
(( fn.contains Kit, 1234 Kit Creek == True ))
|
false
true
true
|
{{ fn.sub_string haystack, 0, 2 }}
{{ fn.sub_string haystack, 7, 7 }}
|
hay
k
|
{{ fn.containsIgnoreCase aaa, bbbaAaccc }}
|
true
|
{{ fn.containsStartsWith aaa, aaaffccffdd }}
|
true
|
{{ fn.containsStartOf ffnnccgg, ffnn }}
|
true
|
{{ fn.isexactly source1, source1 }}
|
true
|
Note: no spaces between commas. {{ fn.replace dddddAAAc,AAA,FFF }}
|
dddddFFFc
|
{{ fn.validate_name }}
{{ fn.validate_name a }}
|
false
true
|
fn.fix_non_ascii : Given a string containing non-ASCII characters and a “from” and “to” characters parameter pair, return a string with “from” characters replaced with “to” characters. This allows for control over the replacement.
3 steps are carried out in the following sequence:
- Map characters in the given string by using the corresponding characters in the “<from>,<to>” string parameter pair.
- Map all “accented” (accent, circumflex, diaeresis, etc.) non-ASCII characters to ASCII characters.
- Map all remaining non-ASCII characters with
_
.
For example:
- string =
Ŧest Nón Asciï
- <from>,<to> =
ï,G
- result =
_est Non AsciG
step 1: from =
ï
is replaced with to =G
.step 2: accented
ó
is replaced with ostep 3: Ŧ is a remaining non-ASCII character and replaced with _.
Example Output {{ fn.fix_non_ascii 'Têst Nón Asciïæ mapping' ,sæ,Ga }} {{ fn.fix_non_ascii 'Ŧest Nón Asciï' }}
'TeGt Non AGciia mapping' '_est Non Ascii'
fn.fix_username : Given a string of characters, return the string with a replacement character:
-
for any character not in the following range:a-zA-Z0-9._-
.A Unified CM Remote Destination name is an example where such a string is required.
Example Output {{ fn.fix_username O'Reilly }}
O-Reilly