KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Toggling letter case selection in 4D Write Pro document
PRODUCT: 4D | VERSION: 17 | PLATFORM: Mac & Win
Published On: October 31, 2018

Here is a utility method to toggle letter cases selection in a 4D Write Pro document:

//---------------------------------------------------------------------------------
// Name: TOGGLE_CASE_WP
// Description: Method will toggle the case (Upper case -> Lower case or opposite)
// of each letter of the selection in a 4D Write Pro document.
// Parameters:
// $1 (POINTER) - Write Pro object
// --------------------------------------------------------------------------------
C_POINTER($1;$writeObj)
C_OBJECT($range)
C_TEXT($str;$newStr;$workingChar)
C_LONGINT($i;$charCode)

If (Count parameters=1)
  $writeObj:=$1
  
  $range:=WP Get selection($writeObj->)
  $str:=ST Get text($writeObj->;$range.start;$range.end)
  
  For ($i;1;Length($str))
  
   $workingChar:=""
   $charCode:=Character code($str[[$i]])
  
   If (($charCode>=65) & ($charCode<=90))
    $workingChar:=Char($charCode+32)
   End if
  
   If (($charCode>=97) & ($charCode<=122))
    $workingChar:=Char($charCode-32)
   End if
  
   If ($workingChar="")
    $newStr:=$newStr+$str[[$i]]
   Else
    $newStr:=$newStr+$workingChar
   End if
  End for
  
  ST SET TEXT($writeObj->;$newStr;$range.start;$range.end)
End if


Example #1: Here is the method when ran to on all the selected plain text:



TOGGLE_CASE_WP (->WriteProArea)


The result is the following:




Example #2: with styled text:



Here is the result after the execution of the method.