Formulas and functions: texts

In the sections getting started with formulas and getting started with functions the basics of this topic are presented. This section is specifically about the use of formulas and functions to edit texts.

Three basic operators in maths - add, subtract, and multiply - are also applicable to text in the Berkeley Studio. Below they are explained, with examples to clarify them. Examples of models that show how to use these functions can be found at the example models.

Adding, multiplying and subtracting texts

In order to add texts to one another, the Berkeley Studio uses the plus sign (+). Being able to add texts to each other is both easy and useful. In general, just state the texts and put a plus sign in between them. You can do this with variables containing text and with plain text:

'Hello ' + 'there' + '!'

is the very same as

'Hello there!'

You can also do the same if you use variables. For now, imagine we have variables name and age. You can then write

'Hello ' + name + ', you are ' + age + ' years old!'

Notice that you have to add you own white spaces in between variables and texts.

Less often you will need to remove some piece of text. In that case, you can use the minus operator (-) to do so. For example,

'Hello there!' - 'there!' = 'Hello'

Please note that the minus operator completely removes all instances! For example:

'Hello there!' - 'e' = 'Hllo thr!'

Furthermore, if you want to multiply text, you can use the multiply operator (*):

'text' * 3 = 'texttexttext'

Basic texts functions

It is beyond the scope of this guide to discuss all possible functions on texts. However, we will present the most used ones and give a couple of examples. An introduction about functions in general can be found at getting started with functions.


The length function will give the length of any given text. Length is this case means the number of characters the text has. For example, ‘hey!’ has a length of four. You can use this function as follows:

length('this is text') = 12
length(name) = 4
length(name + name) = 8

We hereby assumed that variable name has value ‘John’.


The function replacestring will replace a piece of text with another. You have to provide three different texts: the text in which you want to replace something, the text to replace and the text that will replace it. For example:

replacestring('Hello there!', 'there','John') = 'Hello John!'
replacestring('I love icecream', 'love','hate') = 'I hate icecream'

numtostring is a very useful function when working with numbers. The Berkeley Studio will not format numbers by default when showing them on screen or in a document. For example, imagine the user answers a question with 1000000. You might want to format that number, with dots or commas. Some examples:

numtostring(1000000, 'N.,-') = '1.000.000,-'
numtostring(1000000, 'N,.2') = '1,000,000.00'

Note that the last character in the format is the number of decimals.