KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Convert string to character array
PRODUCT: 4D | VERSION: 13.1 | PLATFORM: Mac & Win
Published On: August 24, 2012

Here is a utility method that converts a string into an array of characters:

// ----------------------------------------------------
// Method: stringToCharArray
// Description:
// Converts a string into an array of characters
//
// Parameters:
// $1 (Text) - String to be converted into an array
// $2 (Pointer)- Pointer to the character array
// ----------------------------------------------------

C_TEXT($1;$string)
C_POINTER($2;$charArray_p)
C_LONGINT($stringLength)

$string:=$1
$charArray_p:=$2
$stringLength:=Length($string)

For ($i;1;$stringLength)
   APPEND TO ARRAY($charArray_p->;Substring($string;$i;1))
End for


Below is an example of how the method can be called:

ARRAY TEXT($charArray;0)
stringToCharArray ("this is a test sentence!";->$charArray)


The above code will populate the array $charArray as shown: