FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour remove formatting within a memo field
Posts: 204
Joined: Mon Oct 17, 2005 09:09 PM

remove formatting within a memo field

Posted: Thu Jan 26, 2017 04:19 PM

I am reading a SQL database via ADO.
one of the data Items I'm using is a memo field, with embedded formatting.

here is an example:

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Microsoft Sans Serif;}}
\viewkind4\uc1\pard\f0\fs17 JH - Sue let me know that their rep had noticed that they were not performing the yearly escrow analysis.\par
}

What I wish to preserve is the message without the formatting:

JH - Sue let me know that their rep had noticed that they were not performing the yearly escrow analysis.

Is there a function that will remove these formatting characters automatically?
I noticed that using DBU the memoedit function appears to ignore MOST of these.

Don Lowenstein
www.laapc.com
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM

Re: remove formatting within a memo field

Posted: Thu Jan 26, 2017 05:35 PM
Don

I have used this to remove CRLF and carriage returns .. try this :
Code (fw): Select all Collapse
cText := HardCr( oRs:Fields("Memo"):Value )


HardCR()
Replaces soft carriage returns with hard CRs in a character string.
Syntax
HardCR( <cString> ) --> cConvertedString

Arguments
<cString>
A character string to be converted. Return
The function returns <cString> with all soft carriage returns converted to hard carriage returns.
Description
Soft carriage returns (Chr(141)+Chr(10)) are inserted into a string by MemoEdit() when a line wraps during editing. The string returned from MemoEdit() retains soft carriage returns and is usually stored in a memo field. When such a string must be printed or displayed with another function than MemoEdit(), it is necessary to replace soft carriage returns with hard carriage returns (Chr(13)+Chr(10)) since soft carriage returns are not interpreted as end of line characters.
Note: when a memo field is output using a proportional font, use MemoTran() to replace soft carriage returns with a space character.


Rick Lipkin
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM

Re: remove formatting within a memo field

Posted: Thu Jan 26, 2017 07:37 PM
This function is not perfect, but it is an idea

Code (fw): Select all Collapse
#include "Fivewin.ch"

Function Main()

   local cString
   local cTmp1   := ""
   local nPos1   := 0
   local nPos2   := 0
   
   cString := "{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Microsoft Sans Serif;}}" + ;
    "\viewkind4\uc1\pard\f0\fs17 JH - Sue let me know that their rep had noticed that they were not performing the yearly escrow analysis.\par" + ;
    "}"
    
   cString := StrTran( cString, CRLF, "" )
   nPos1 := At( "{\", cString )
   if !Empty( nPos1 )
      nPos2 := At( "}", cString )
      if !Empty( nPos2 )
         cTmp1   := Substr( cString, nPos1, nPos2 - nPos1 + 1 )
         cString := StrTran( cString, cTmp1, "" )
         cString := StrTran( cString, "}", "" )
         cString := StrTran( cString, "{", "" )
         nPos1   := At( "\", cString )
         if !Empty( nPos1 )
            nPos2 := At( Chr( 32 ), cString )
            cTmp1   := Substr( cString, nPos1, nPos2 - nPos1 + 1 )
            cString := StrTran( cString, cTmp1, "" )
         endif
         cString := StrTran( cString, "\par", "" )
      endif
   endif
   ? cString

Return nil
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 204
Joined: Mon Oct 17, 2005 09:09 PM

Re: remove formatting within a memo field

Posted: Thu Jan 26, 2017 09:07 PM

Cristobal,

That is essentially what I did.
thanks for providing your input.

Don.

Don Lowenstein
www.laapc.com
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM

Re: remove formatting within a memo field

Posted: Thu Jan 26, 2017 09:59 PM

You are not going to have a TRichEdit control?
It's just going to have a formatted string, right?

Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 204
Joined: Mon Oct 17, 2005 09:09 PM

Re: remove formatting within a memo field

Posted: Fri Jan 27, 2017 12:46 AM

correct.

I'm wishing to print the memo data on a report without all of the embedded formatting.

Don Lowenstein
www.laapc.com
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM

Re: remove formatting within a memo field

Posted: Fri Jan 27, 2017 12:49 AM

What I mean is that the string does not read from a RichEdit control, does it?

Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces

Continue the discussion