remove formatting within a memo field

Post Reply
User avatar
don lowenstein
Posts: 196
Joined: Mon Oct 17, 2005 9:09 pm
Contact:

remove formatting within a memo field

Post by don lowenstein »

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
User avatar
Rick Lipkin
Posts: 2397
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: remove formatting within a memo field

Post by Rick Lipkin »

Don

I have used this to remove CRLF and carriage returns .. try this :

Code: Select all

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
User avatar
cnavarro
Posts: 5792
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: remove formatting within a memo field

Post by cnavarro »

This function is not perfect, but it is an idea

Code: Select all


#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


C. Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
Si alguien te dice que algo no se puede hacer, recuerda que esta hablando de sus limitaciones, no de las tuyas.
User avatar
don lowenstein
Posts: 196
Joined: Mon Oct 17, 2005 9:09 pm
Contact:

Re: remove formatting within a memo field

Post by don lowenstein »

Cristobal,

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

Don.
Don Lowenstein
www.laapc.com
User avatar
cnavarro
Posts: 5792
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: remove formatting within a memo field

Post by cnavarro »

You are not going to have a TRichEdit control?
It's just going to have a formatted string, right?
C. Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
Si alguien te dice que algo no se puede hacer, recuerda que esta hablando de sus limitaciones, no de las tuyas.
User avatar
don lowenstein
Posts: 196
Joined: Mon Oct 17, 2005 9:09 pm
Contact:

Re: remove formatting within a memo field

Post by don lowenstein »

correct.

I'm wishing to print the memo data on a report without all of the embedded formatting.
Don Lowenstein
www.laapc.com
User avatar
cnavarro
Posts: 5792
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: remove formatting within a memo field

Post by cnavarro »

What I mean is that the string does not read from a RichEdit control, does it?
C. Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
Si alguien te dice que algo no se puede hacer, recuerda que esta hablando de sus limitaciones, no de las tuyas.
Post Reply