Built-in Functions

You can embed raw javascript in your patterns, by surrounding it with 'bee-stings' (i.e. wrap it in <% and %> )

This is very powerful. Your patterns can do everything javascript can do.

You rarely need that much power though. All you need most of the time is a few simple functions to manipulate text.

In the general help there is an example of using the 'toSentenceCase' function -- this is handy when you want to capitalize the first letter of the first word in a bunch of text.

Here are some other functions that are available in NimbleText.

All of these are available from the ultra handy 'function' menu!

 

'toUpperCase'

The built-in function toUpperCase changes your text to UPPER CASE.

So if the input data said:

All work and no play makes jack a dull boy

...then the output of this pattern:

try it →
    <% $row.toUpperCase() %>

would be:

ALL WORK AND NO PLAY MAKES JACK A DULL BOY

 

'toLowerCase'

The built-in function toLowerCase changes your text to lower case.

So if the input data said:

ALL WORK AND NO PLAY MAKES JACK A DULL BOY

...then the output of this pattern:

try it →
    <% $row.toLowerCase() %>

would be:

all work and no play makes jack a dull boy

 

'toTitleCase'

The built-in function toTitleCase changes your text to Title Case, meaning that each word is capitalized.

So if the input data said:

All work and no play makes jack a dull boy

...then the output of this pattern:

try it →
    <% $row.toTitleCase() %>

would be:

All Work And No Play Makes Jack A Dull Boy

 

'toPascalCase'

The built-in function toPascalCase changes your text to PascalCase, meaning that each word is capitalized and then spaces are removed.

So if the input data said:

All work and no play makes jack a dull boy

...then the output of this pattern:

try it →
    <% $row.toPascalCase() %>

would be:

AllWorkAndNoPlayMakesJackADullBoy

 

'toCamelCase'

The built-in function toCamelCaseCase changes your text to camelCase, which is just like PascalCase, but more camel-like. Technically, the difference is that the first letter of the word is not capitalized. It is a small difference, but worth an extra function..

So if the input data said:

All work and no play makes jack a dull boy

...then the output of this pattern:

try it →
    <% $row.toCamelCase() %>

would be:

allWorkAndNoPlayMakesJackADullBoy

 

'toSentenceCase'

The built-in function toSentenceCase changes your text to Sentence case, meaning that the first word is capitalized, and all of the other words are left alone.

So if the input data was all lower case, and for example said:

all work and no play makes jack a dull boy

...then the output of this pattern:

try it →
    <% $row.toSentenceCase() %>

would be:

All work and no play makes jack a dull boy

 

'toWords'

The built-in function toWords splits any PascalCase or camelCase words into their constituent parts (by inserting spaces before each capital letter)

So if the input data said:

PersonName
ManagerRole

...then the output of this pattern:

try it →
    <% $row.toWords() %>

would be:

Person Name
Manager Role

 

'reverse'

The built-in function reverse reverses the order of your text, for that 'gone crazy' look.

So if the input data said:

All work and no play makes jack a dull boy

...then the output of this pattern:

try it →
    <% $row.reverse() %>

would be:

yob llud a kcaj sekam yalp on dna krow llA

 

'replace'

The built-in function replace lets you replace one value with another.

So if the input data said:

All work and no play makes jack a dull boy

...then the output of this pattern:

try it →
    <% $row.replace('a dull boy','an axe-wielding maniac') %>

would be:

All work and no play makes jack an axe-wielding maniac

You can also perform multiple replaces, one after the other.

For example, this pattern:

try it →
<% 
$row = $row.replace('a dull boy','an axe-wielding maniac'); 
$row = $row.replace('an axe','a teddy bear');
$row 
%>

Produces the result:

All work and no play makes jack a teddy bear-wielding maniac

Or, you can chain the replacements together, one after the other like so:

try it →
<% 
$row
  .replace('a dull boy','an axe-wielding maniac')
  .replace('an axe','a teddy bear') 
%>

...for the same result as the previous example.

The 'replace' function is part of javascript, it isn't something extra that NimbleText has added on top (unlike the toPascalCase function, for example)

Replace can also take a regular expression as the first parameter.

For example you could turn all vowels into your favourite vowel sound ('oo'), with a pattern like this:

try it →
<%  $row.replace(/[aeiou]/ig,'oo') %>

Which produces the lyrically pleasing:

ooll woork oond noo plooy mookoos joock oo dooll booy

For a complete reference on using javascript's replace method, I recommend the Javascript Replace documentation at the Mozilla Developer Network.

 

'htmlEncode'

The built-in function htmlEncode performs 'html Encoding' on your text.

So if the input data said:

Ten < Twenty & is > Five

...then the output of this pattern:

    <% $row.htmlEncode() %>

would be:

Ten &lt; Twenty &amp; is &gt; Five

 

'htmlDecode'

The built-in function htmlDecode decodes text that has previously been html encoded.

So if the input data said:

Ten &lt; Twenty &amp; is &gt; Five

...then the output of this pattern:

    <% $row.htmlDecode() %>
    

would be:

Ten < Twenty & is > Five

 

'urlEncode'

The built-in function urlEncode lets you url Encode your text.

So if the input data said:

http://google.com/

...then the output of this pattern:

    <% $row.urlEncode() %>

would be:

http%3A%2F%2Fgoogle.com%2F

Or if the input data said:

A B C D E F

...then the output would be:

A%20B%20C%20D%20E%20F

 

'urlDecode'

The built-in function urlDecode decodes text that has previously been url encoded.

So if the input data said:

http%3A%2F%2Fgoogle.com%2F

...then the output of this pattern:

    <% $row.urlDecode() %>

would be:

http://google.com/

Or if the input data said:

A%20B%20C%20D%20E%20F

...then the output would be:

A B C D E F

 

'xmlEncode'

The built-in function xmlEncode encodes special characters that are not permitted inside XML tags or attributes. Specifically it makes the following changes:

From To
< &lt;
> &gt;
" &quot;
& &amp;
' &apos;

So if the input data said:

All <em>work</em> & 'no' play makes jack a "dull" boy

...then the output of this pattern:

    <% $row.xmlEncode() %>

would be:

All &lt;em&gt;work&lt;/em&gt; &amp; &apos;no&apos; play makes jack a &quot;dull&quot; boy


 

 

'xmlDecode'

The built-in function xmlDecode decodes special characters that were encoded by an Xml Encoding process. Specifically it makes the following changes:

From To
&lt; <
&gt; >
&quot; "
&amp; &
&apos; '

So if the input data said:

All &lt;em&gt;work&lt;/em&gt; &amp; &apos;no&apos; play makes jack a &quot;dull&quot; boy

...then the output of this pattern:

    <% $row.xmlDecode() %>

would be:

All <em>work</em> & 'no' play makes jack a "dull" boy

 

'split'

The built-in function split lets you separate a string into an array of substrings, at every instance of a separator. (The separator can be a single character, a string, or even a regular expression!)

So if the input data said:

Mr Jones,2012-01
Professor Smith,2014-02

...then the output of this pattern:

<% $0.split(' ')[1] %>, <% $1.split('-')[0] %>

would be:

Jones,2012
Smith,2014

See also: Mozilla's documentation about split.

 

'charAt'

The built-in function charAt let you grab any character, by its index number (starting at 0).

So if the input data said:

All work and no play makes jack a dull boy

...then the output of this pattern:

    <% $row.charAt(0) %>

would be:

A

...because character 0 (the first character) is 'A'.

 

'indexOf'

The built-in function indexOf returns the index (the location) of the first occurrence of the specified string It is case sensitive.

Some programming languages call their indexOf function 'find', 'Pos', 'Locate' or 'InStr' (see wikipedia string functions "find").

So if the input data said:

All work and no play makes jack a dull boy

...then the output of this pattern:

    <% $row.indexOf('no play') %>

would be:

13

...because 'no play' appears starting at index 13.

 

'lastIndexOf'

The built-in function lastIndexOf returns the index (the location) of the LAST occurrence of the specified string. It is case sensitive.

Some programming languages call their lastIndexOf function 'rfind', 'rindex', 'strrpos' or 'InStrRev' (see wikipedia string functions "rfind").

So if the input data said:

All work and no play makes jack a dull boy

...then the output of this pattern:

    <% $row.lastIndexOf('ll') %>

would be:

36

...because the 'll' in "dull" is at index 36.

 

'slice'

The built-in function slice returns a section of a string, from a starting position up to an optional end position .

So if the input data said:

All work and no play makes jack a dull boy

...then the output of this pattern:

    <% $row.slice(4,8) %>

would be:

work

Alternatively, you can specify a negative starting position to read from the end of the string.

Here is a table of examples:

Example Result Explanation
<% $row.slice(27) %> jack a dull boy everything after the first 27 characters
<% $row.slice(-15) %> jack a dull boy everything after the (15th last) character
<% $row.slice(27,31) %> jack everything from the 27th to 31st character
<% $row.slice(27,-11) %> jack everything from the 27th to the (11th last) character
<% $row.slice(-15,-11) %> jack everything from the (15th last) to the (11th last) character

 

'substr'

The built-in function substr returns a section of a string, from a starting position, for a specified number of characters. It is similar to slice, but instead of specifying the end index, you specify the number of characters to take.

So if the input data said:

All work and no play makes jack a dull boy

...then the output of this pattern:

    <% $row.substr(4,4) %>

would be:

work

 

'left'

The built-in function left allows you to take the first n characters from a string. It is provided for convenience to people with a background in SQL, or Visual Basic, or any platform that has a 'left' function. It is a simple wrapper on the substr function.

So if the input data said:

All work and no play makes jack a dull boy

...then the output of this pattern:

    <% $row.left(8) %>

would be:

All work

 

'right'

The built-in function right allows you to take the last n characters from a string. It is provided for convenience to people with a background in SQL, or Visual Basic, or any platform that has a 'right' function. It is a simple wrapper on the substr function.

So if the input data said:

All work and no play makes jack a dull boy

...then the output of this pattern:

    <% $row.right(10) %>

would be:

a dull boy

 

'lpad'

The built-in function lpad allows you to pad a string with characters on the left, to make a fixed-width value that is right-aligned. It is provided for convenience to people with a background in Oracle, Visual Basic, or any platform that has a 'left pad' function. It is commonly used with numeric values. Here's a detailed example.

So if the input data said:

12,23
14,25

...then the output of this pattern:

    x<% $0.lpad(7) %>x,y<% $1.lpad(7,'0') %>y
    

would be:

x     12x,y0000023y
x     14x,y0000025y

 

'rpad'

The built-in function rpad allows you to pad a string with characters on the right, to make a fixed-width value that is left-aligned. It is provided for convenience to people with a background in Oracle, Visual Basic, or any platform that has a 'right pad' function. It is commonly used with non-numeric values. Here's a detailed example.

So if the input data said:

1,3
2,25
3,128
4,545
5,613
6,723
7,840
8,1052

...then the output of this pattern:

    <% ("Chapter " + $0).rpad(20,'.') %>pg <% $1.lpad(4,' ') %>
    

would be:

Chapter 1...........pg    3
Chapter 2...........pg   25
Chapter 3...........pg  128
Chapter 4...........pg  545
Chapter 5...........pg  613
Chapter 6...........pg  723
Chapter 7...........pg  840
Chapter 8...........pg 1052

 

'dateFormat'

The built-in function dateFormat (also Date.prototype.format) allows you to format a date type, in whatever way you prefer. There is a separate help page that documents all of the ways you can format a date.

This feature is only available in the Desktop version. (Compare versions).

So if the input data said:

2016-11-25

...then the output of this pattern:

<% $0.dateFormat('ddd, dd mmm yyyy') %>

would be:

Fri, 25th Nov 2016.

 


Further help

You can also get general help, help on all the symbols and keywords, or on the built-in functions, filtering with a where clause, help with the powerful command-line automation, or applying custom formats to your dates and times.

You need to purchase a license to unlock all the features in NimbleText.

If you haven't downloaded NimbleText yet, then for added power, privacy and versatility I sincerely think you should download it now.

Download NimbleText