Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing ASCII characters from memo field

Status
Not open for further replies.

AWilliams

Programmer
Mar 20, 2002
10
CA
I am copying data from a foxpro table to a text file along with the memo fields data in the table.

The problem I have is there are several ASCII characters within the memo field which I want to remove, such as a Capital A Tilde - Ã, Small a Tilde - ã, Capital AE ligature - Æ.

It appears that the contents of the memo field were pasted in from some other application along with these characters.

With this code:

<code>
#DEFINE Atilde CHR(195)
lnDelChar=OCCURS(Atilde,lcMemo)
lcMemo=STRTRAN(lcMemo,Atilde,'')
</code>

I can remove the Capital A tilde but I need to search the entire memo field for several more ASCII characters before the contents are written to the text file. Any suggestions on how to best proceed.

I have attached some of the code where the memo field processing occurs.

<code>
CASE lcType = 'M' && Process the Memo Fields
lnMemoLines = MEMLINES(EVALUATE(laGetFields(lnCount,1)))

FOR lnLoop = 1 TO lnMemoLines
IF lnLoop < lnMemoLines

#DEFINE Atilde CHR(195)
lnDelChar=OCCURS(Atilde,lcMemo)
lcMemo=STRTRAN(lcMemo,Atilde,'')

lcMemo = lcMemo + ;
ALLTRIM(MLINE(EVALUATE(laGetFields(lnCount, 1)), ;
lnLoop)) + ' '
ELSE

lcMemo = lcMemo + ;
ALLTRIM(MLINE(EVALUATE(laGetFields(lnCount, 1)), ;
lnLoop))
ENDIF
ENDfor

lcString = lcMemo
lcMemo = ''
</code>
 
Hi

You could try using chrtran(). Then you can list as many characters as you like (there is a limit somewhere!)

Code:
lcMemo=CHRTRAN(lcMemo,Atilde+othorn+oelig+capoelig+aangstrom,'')

Where I have added some extra dodgy character names. All characters mentioned will be stripped from lcMemo

Derren
[Mediocre talent - spread really thin]
 
AWilliams,
Basically, your problem is an age-old one. What you really want to do is to strip off characters above or below an ASCII value range. The would be, all characters with an ASCII value less than 32 (the &quot;space&quot; value) and greater than 126 (the tilde character). This basically covers all the values you'll see on your keyboard, including captial letters, and the SHIFT key values, like # for SHIFT-3). These values are all &quot;Legal&quot;. So, all you have to do is replace any value with '' that doesn't match your value. As derren suggested, the CHRTRANS is a good function to use this with. I'll modify his suggestion just slightly:

lcMemoFix = ''
FOR lnCheckChar = 1 to LEN(ALLTRIM(lcMemo))
lcMemoFix = IIF(ASC(SUBSTR(lcMemo,lnCheckChar,1)) < 32;
.OR. ASC(SUBSTR(lcMemo,lnCheckChar,1)) > 126,;
'',SUBSTR(lcMemo,lnCheckChar,1))
ENDFOR

What this will do is test the &quot;ASCII&quot; value of every chracter in your string, and delete it if it is not in the &quot;Valid&quot; range. If it is valid, then it gets added to the &quot;New&quot; lcMemoFix value. To keep the &quot;lcMemo&quot; variable name, after the ENDFOR, simply add:

lcMemo = lcMemoFix

Then, Bob's your uncle.

Best Regards,
Scott

Please let me know if this has helped [hammer]
 
Also, on another note... depending on your needs, and formatting of data, you may chose to not test for values in the low ascii range. They may, or may not be, a problem depending on your data. Low values like CHR(12), is a Page Eject, and are often found to be a problem in MEMO fields, but CHR(13) is a ENTER key, and you may have a need for that. You can do one of two things, either, don't test for the low range (simply remove the test for values below 32, that I put in the above code), or add to the code above, to NOT include the ASCII value 13, effectively, keeping the &quot;CR/LF&quot; values in your memo fields.

Best Regards,
Scott

Please let me know if this has helped [hammer]
 
Scott

Appreciate your help with the code. I tried incorporating it in my code but it when executed none of the memo field is copied to the text file.

Any suggstions?
 
AWilliams,
Make sure that you are referencing the field of your Memo correctly. I selected some &quot;Arbitrary&quot; names for the memo manipulation. For easiest code modification, if you have a memo field in a table, let's call the table CUSTOMER, and the memo field &quot;INFO&quot;, you should issue first:

lcMemo = CUSTOMER.INFO

place this before the code I wrote above, and then, after the code, instead of lcMemo = lcMemoFix, issues

REPLACE CUSTOMER.INFO WITH lcMemoFix

Best Regards,
Scott

Please let me know if this has helped [hammer]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top