/

 

The manual

Self-training

Experimentation

Contact

 

Language

Strings

Get the length of a string:

var Str s
var Int i
...
i := s len

Get the substring of length 12, starting at character number 5:

var Str s1 s2
...
s2 := s1 5 12

As is usual in computers, the number of the first character is zero, not one.
If the string is shorter than the number of characters requested, the entire end of the string will be provided.

Warning: strings are encoded in UTF-8. 'len' does not return the actual number of characters, but the number of bytes in the string. Idem concerning the function of extraction of substring.

Replace:

var Str s1 s2
s2 := replace s1 "." ","

Complete to the size requested by aligning to the right or to the left:

var Str s1 s2
s2 := left s1 6 "0"
s2 := right s1 6 "0"

Notes:
The last parameter must be a 1 character string.
If the starting string is longer than the requested size, it will be returned identically and not truncated to the requested length.

Remove all accents and all non-ASCII symbols:

var Str s1 s2
s2 := ascii s1

Put in upper or lower case:

var Str s1 s2
s2 := upper s1
s2 := lower s1

Warning: the 'upper' and 'lower' functions convert only unaccented letters.

Determine if the chain s1 contains the substring s2:

var Str s1 s2
var CBool c
...
c := s1 contains s2

We also have a more powerful decomposition instruction:

var Str s1
..
if (s1 parse "abc" any:(var Str head) "def")
  ...

Documentation of the 'parse' function on the Pliant website
     See the 'Parsing' paragraph

In a report, we want to perform a classification on two columns, for example the 'year' column followed by the 'name' column, we can use the 'lexico' function whose property is to return a character string that preserves the order of comparison:

lexico annee nom

Avant 2024, la syntaxe était :

lexico:annee+lexico:nom

From: Hubert Tonneau   2013/08/18 21:08:40

Compléter la documentation de 'parse'