remove formatting within a memo field

remove formatting within a memo field

Postby don lowenstein » Thu Jan 26, 2017 4: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
User avatar
don lowenstein
 
Posts: 197
Joined: Mon Oct 17, 2005 9:09 pm

Re: remove formatting within a memo field

Postby Rick Lipkin » Thu Jan 26, 2017 5:35 pm

Don

I have used this to remove CRLF and carriage returns .. try this :
Code: Select all  Expand view

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

Re: remove formatting within a memo field

Postby cnavarro » Thu Jan 26, 2017 7:37 pm

This function is not perfect, but it is an idea

Code: Select all  Expand view


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

Re: remove formatting within a memo field

Postby don lowenstein » Thu Jan 26, 2017 9:07 pm

Cristobal,

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

Don.
Don Lowenstein
www.laapc.com
User avatar
don lowenstein
 
Posts: 197
Joined: Mon Oct 17, 2005 9:09 pm

Re: remove formatting within a memo field

Postby cnavarro » Thu Jan 26, 2017 9: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
User avatar
cnavarro
 
Posts: 6548
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: remove formatting within a memo field

Postby don lowenstein » 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
User avatar
don lowenstein
 
Posts: 197
Joined: Mon Oct 17, 2005 9:09 pm

Re: remove formatting within a memo field

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


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 79 guests