CA SDM  Spel - String functions

Blog Post created by TMACUL Champion on Oct 15, 2015

Casting String between data types: All (supported)  / Todos os tipos de conversões de string para outro tipo de dados são suportados.


strlen  - int strlen (string target)

Get string length

Returns the length of the string str.




The length of a string is determined by the terminating null-character: A string is as long as the number of characters between the beginning of the string and the terminating null character (without including the terminating null character itself).



strlen ("Hello world"); // len = 11



sindex - int sindex (string target, string regex [, int start])

Searching strings

Returns the position of string



intPos = sindex ("Hello world", "l");      // intPos =   2

intPos = sindex ("Hello world", "l", 6);  // intPos =   9

intPos = sindex ("Hello world", "Macul", 6);  // intPos = -1 (not found)



substr - string substr (string target, string regex)

Searching strings

Returns the string



Returns the matching part of the string.

bar = substr ("Hello world", " .*l"); // bar = " worl"



string gsub (string target, string regex, string repl)
Returns a copy of str with the all occurrences of pattern substituted



int split (string dest [], string target, string regex)

segregate string

Returns String array


  1. string dest [] - variable
  2. string target - Required. String expression containing substrings and delimiters.
  3. string regex - Any string of characters used to identify substring limits.



split(var, "1 2 3", " ") returns {1, 2, 3}




int extract(string dest[], string target, string regex)

Puts pieces of the string which match marked parts of the regex into. It returns the number of pieces.



string downcase (string source)


Returns the lowercase of a string.


downcase("HELLO WORLD")   returns "hello word"



string upcase (string source)


Returns the uppercase of a string.



uppercase("Hello World")   returns "HELLO WORLD"



void printf (string format, ...)



string format (string format, ...)



void sprintf (string result, string format, ...)

Composes a string with the same text that would be printed if format was used on printf, but instead of being printed, the content is stored as string in the buffer pointed by str



void sscanf (string target, string format, ...)

Reads data from s and stores them according to parameter format into the locations given by the additional arguments, as if scanf was used, but reading from s instead of the standard input (stdin).



The additional arguments should point to already allocated objects of the type specified by their corresponding format specifier within the format string.




void logf (level, string format, ...)

Conditionally write to the log.


Format and ... are as in printf



string expand (string format)

Expand variable references in a string. This is similar to '$' expansion in a shell. Words in the string to be expanded start with a tag character and are optionally surrounded by {}. For example $NX_ROOT or $ {NX_ROOT}.



Veja também:

Where can I find Spel functions documentation?