KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Getting started with data cleansing or character referencing
PRODUCT: 4D | VERSION: | PLATFORM: Mac & Win
Published On: December 20, 2002

Compatibility: Version 6.7.x and 6.8.x

Often it is necessary to clean data that has been entered or imported in order to remove unwanted characters. This tech tip presents a simple routine to get you started considering this concept, and reviews the use of character referencing.

Suppose you had data in which there were double quotes that you wanted to strip out. The following routine will perform this simple data cleansing task. This routine makes use of the character referencing symbols (◊ " on the Mac, or [[ ]] on Windows) to reference each character of the string being worked on by its position number within the string. This routine would be passed the string to be cleansed, for example from a field, and return the modified string, to be assigned back to the field.


`Parameters:
`$1 The string to be cleaned
`$0 The string after being cleaned

C_TEXT($tStringToClean;$1;$0)
C_INTEGER($i;$iStringLength)
C_STRING(1;$sQuote)

$tStringToClean:=$1
$iStringLength:=Length($tStringToClean)
$sQuote:=Char(Double quote ) `Convert the constant to a character

For ($i;1;$iStringLength)

 Case of
  : ($tStringToClean◊$i"#$sQuote) `$tStringToClean◊$i" is the character by number for this pass through the loop.
  $0:=$0+$tStringToClean◊$i"
 End case

End for