1. Home
  2. Iterop Design
  3. Use a script
  4. Information on character strings (Bean JUEL)

Information on character strings (Bean JUEL)

In IteropScript (based on JavaScript), certain special characters are interpreted, i.e. they have a meaning within the code in which they are located. This is also the case if they are located in a string.

For example:

var myVarJs = "Voici un " dans ma chaîne";

This piece of code will cause an error at runtime, because the

in the middle of the string will be interpreted to mean the end of the string. The rest will then be considered as code but means nothing, which will cause, in fine, an error.

The different special characters interpreted in a string

The backslash.

The backslash has two uses: it allows to escape the interpretation of the character that follows it, and also combined with a specific letter, act as a special character :

Attention

It is therefore necessary to be very careful when using the character antislash: “ \ “. We advise to use a simple slash (“/”) in your business repository data for example whenever possible.

The use of this one allows to escape a character which would have a role in the string. Indeed:

  • \\ “Drop a backslash.
  • \”Drop a quote.
  • \Drop an apostrophe…

Let’s take an example with the character “:

var myVar = "Voici un \" dans ma chaîne";

MyVar will have the value:

Voici un " dans ma chaîne

the special characters are :

  • \n-New line.
  • \Back to the line.
  • \v: Vertical tabulation.
  • \Tabulation.
  • \b: Tab back.
  • \Form feed.

The dangers of special characters

In order to facilitate the exchange of data, the system will use the format JSON (JavaScript Object Notation – Object Notation from JavaScript). JSON is an independent text format based on a subset of the JavaScript programming language.

Even if the json is based on JavaScript, they are different on a number of points, but the one we are interested in here is the following:

-> Special character handling

The JSON supports the escape syntax of the backslash for special characters. But not all characters are recognized by the JSON format.

Only these special characters are taken into account:

  • \n-New line.
  • \Back to the line.
  • \Tabulation.

The list of characters accepted by JSON is well shorter than that of JavaScript.

The JavaScript to JSON translation functions interpret strings in JSON format. But these functions are very strict and will generate an exception when they encounter a character not expected by the specification.

There is therefore a consequent risk of misinterpretation when using special characters in your various scripts.

Information message

To avoid any interpretation problems, we advise to use backslashes only if it is absolutely necessary and to prioritize slashes.

Updated on 13 November 2020

Was this article helpful?

Related Articles

Need Support?
Can't find the answer you're looking for?
Contact Support