KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Get plain text from Write Pro object
PRODUCT: 4D | VERSION: 16 | PLATFORM: Mac & Win
Published On: January 19, 2017

This is a utility method to extract the text contents in a Write Pro object:

// --------------------------------------------------------------------------------
// Name: WP_GET_PLAIN_TEXT
// Description: Method will extract the contents of the Write Pro object and
// return plain text.
// Input:
// $1 (POINTER) - Pointer to the 4D Write Pro object
// Output:
// $0 (TEXT) - Extracted text from the Write Pro object
// --------------------------------------------------------------------------------
C_POINTER($1;$wpPtr)
C_TEXT($0)
C_TEXT($str;$wStr;$tStr)
C_LONGINT($posBodyBegin;$pos1;$pos2;$posBodyEnd)

If (Count parameters=1)
   
    $wpPtr:=$1
   
    WP EXPORT VARIABLE($wpPtr->;$str;wk web page html 4D)
   
    $posBodyBegin:=Position("<body>";$str)+6
    $posBodyEnd:=Position("</body>";$str)
    $tStr:=""
   
    Repeat
     $pos1:=Position(">";$str;$posBodyBegin)+1
     $pos2:=Position("<";$str;$pos1)
     $wStr:=Substring($str;$pos1;$pos2-$pos1)
     $tStr:=$tStr+$wStr
     $posBodyBegin:=$pos2+1
    Until ($posBodyEnd=$pos2)
   
    $tStr:=Replace string($tStr;"\t";"")
    $tStr:=Replace string($tStr;"&lt";"<") // Less than
    $tStr:=Replace string($tStr;"&gt";">") // Greater than
    $tStr:=Replace string($tStr;"&amp";"&") // Ampersand
    $0:=$tStr
End If


Here is a Write Pro that contains text:



Code to extract the text from the Write Pro object:
C_TEXT($text)

$text:=WP_GET_PLAIN_TEXT (->WriteProArea)



Output of the text: