Chapter 15 ObjectScript - String Functions

Chapter 15 ObjectScript - String Functions

String functions

ObjectScriptThere is also an extensive set of functions for working with strings efficiently:

  • $EXTRACTReturn or replace a substring using character counting.
  • $FINDFinds a substring by value and returns an integer specifying its ending position in the string.
  • $JUSTIFYReturns a right-justified string, padded with spaces on the left.
  • $ZCONVERTConvert a string from one form to another. It supports case conversion (to uppercase, lowercase, or title case) and encoding conversion (between various character encoding styles).
  • $TRANSLATEModifies the given string by performing character-by-character replacement.
  • $REPLACEPerforms a string-by-string replacement in a string and returns a new string.
  • $PIECEReturns a substring from a character-delimited string (often called a segmented string). Here's how to extract a substring:
 SET mystring="value 1^value 2^value 3"
 WRITE $PIECE(mystring,"^",1)
  • $LENGTHReturns the number of characters in the specified string or the number of delimited substrings in the specified string, depending on the arguments used.
 SET mystring="value 1^value 2^value 3"
 WRITE !, "Number of characters in this string: " 
 WRITE $LENGTH(mystring)
 WRITE !, "Number of pieces in this string: "
 WRITE $LENGTH(mystring,"^")

Use multidimensional arrays

The following functions can be used to process entire multidimensional arrays:

  • $ORDERAllows sequential access to each node in a multidimensional array.
  • $QUERYEnables access to each node and child node in the array, and moves up and down the child nodes.

To work with a single node from an array, you can use any of the functions described previously. especially:

  • $DATACan indicate whether a given node exists and whether the given node has children.
  • $GETGet the value of the given node, otherwise get the default value.

Character Values

Sometimes, when creating a string, you need to include characters that cannot be typed. For these, it is possible to use $CHAR.

Given an integer, $CHARreturn the corresponding ASCIIor Unicodecharacter. Common uses:

  • $CHAR(9)is a tab character.
  • $CHAR(10)is a newline character.
  • $CHAR(13)It's the carriage return character.
  • $CHAR(13,10)It's a carriage return and line feed pair.

Function $ASCIIreturns ASCIIthe value of the given character.

Guess you like

Origin blog.csdn.net/yaoxin521123/article/details/132633964