KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: How to strip out the leading spaces from text
PRODUCT: 4D | VERSION: 11.6 | PLATFORM: Mac & Win
Published On: April 9, 2010

Here is a quick code snippet for stripping out the leading spaces from text:

C_TEXT($1;$string_t)
C_TEXT($0)
C_LONGINT($tempLength_l)
$string_t:=$1
Repeat
  If (Substring($string_t;1;1)=" ")
    $tempLength_l:=Length($string_t)
    $string_t:=Substring($string_t;2;$tempLength_l-1)
  end if
Until (Substring($string_t;1;1)#" ")
$0:=$string_t




Although it is less easy to read, the above code can be shortened by a couple lines by removing the $tempLength_l variable from the code. Here is an example:

C_TEXT($1;$string_t)
C_TEXT($0)
$string_t:=$1
Repeat
  If (Substring($string_t;1;1)=" ")
    $string_t:=Substring($string_t;2;Length($string_t)-1)
  end if
Until (Substring($string_t;1;1)#" ")
$0:=$string_t




If the above code is saved as a project method named "StripLeadingSpaces" an example call would be:

C_TEXT($return)
$return:=StripLeadingSpaces("      Some Test With Leading Spaces!")


After calling this method $return would then equal "Some Test With Leading Spaces!".