Removing characters from a text entry box when saving

Hi All

A number of our users cut and paste text into a text entry box that contains unprintable characters - and that really mucks things up.

I am wanting to remove all unprintable characters with the exception of alphabetic, and numeric characters and <C/R> and <L/F> before saving the record.

I have CapeSoft stringtheory and have tried using remove() to no avail.

Anyone have a simple way of achieving this?

G

You could do something like below code. I was putting this text into RTF so wanted to get rid of Curly and Backslash. Another thing this does it get rid of Returns on the End. Many times uses will press enter a few times trying to tab out leaving white on the end that you don’t want.

TextAccepted  PROCEDURE (*STRING TextBlock, SHORT SkipOnAcceptAll=1)
J           LONG, AUTO
FoundEnd    SHORT
  CODE
  IF SkipOnAcceptAll AND 0{PROP:AcceptAll} THEN RETURN.
  LOOP J = LEN(CLIP(TextBlock)) TO 1 BY -1
       IF ~FoundEnd AND TextBlock[J] <= CHR(32)
           TextBlock[J] = ''   !remove trailing white space 13,10,9,32
       ELSE
           FoundEnd = True
           CASE VAL(TextBlock[J])
           OF 123 ; TextBlock[J]='['    !123  OF '{{'  RTF problem
           OF 125 ; TextBlock[J]=']'    !125  OF '}'
           OF 92  ; TextBlock[J]='/'    !92   '\'      flip \ to / for less RTF problems
           OF 13    !ok
           OF 10    !ok
           OF 0 TO 31  ; TextBlock[J]=''      !Tabs and low ASCII to Space
           OF 129 OROF 160 ; TextBlock[J]=''  !a pasted 13,10 ends up as 81h or 129, 160=Hard Space
           END
       END !IF

  END
  DISPLAY
  RETURN

I wonder if KeepChars() is what you want? https://www.capesoft.com/docs/StringTheory/StringTheory.htm#KeepChars

Simple questions sometimes lead to complicated answers.
In this case there are 2 thoughts in play;
A) What exactly is an “unprintable” character?
B) What encoding is being used for the text that is pasted? For example if they paste from a utf-8 block of code, into a clarion (ANSI) text box, then you’re either going to see visual artifacts or “incorrect letters”.

Obviously you can use StringTheory RemoveChars (not Remove), or KeepChars, but the root of your problem may be more complex, and possibly benefit from ToAnsi instead.

Until you really understand the nature of the problem it’s difficult to suggest the optimal solution.

Hello Bruce
The full details of my requirement is:
I need to post an XML stream into Quickbooks from Clarion, but Quickbooks will only allow digits, alphabetic characters plus <C/R> and <L/F>. Everything else seems to crash the upload.

My SQL Text field feeds into an invoice line description in Quickbooks.

What I have found is that users copy and paste into my app from a word document, or spreadsheet - and that then bombs out the XML import process - so I need to strip everything else that they could possible have pasted into the text field.

Then just use KeepChars.
As in
st.KeepChars(‘01234567890abcdefghijklmnopqrstuvwxyzABCEDFGHIJKLMNOPQRSTUVWXYZ’)
https://www.capesoft.com/docs/StringTheory3/StringTheory.htm#KeepChars

Hello Bruce

Thank you. How do I keep <C/R> and <L/F>, can I add that into the string too?

i.e.

st.KeepChars(‘01234567890abcdefghijklmnopqrstuvwxyzABCEDFGHIJKLMNOPQRSTUVWXYZ’&’<10>’&’<13>’)

you can add absolutely anything you like to the string. You might ant to include spaces, and some basic punctuation (periods, commas etc) as well.

Also, you don’t have to do the string concatenation as you did there, just put those chars in the string.

st.KeepChars(‘., 01234567890abcdefghijklmnopqrstuvwxyzABCEDFGHIJKLMNOPQRSTUVWXYZ<13,10>’

cheers
Bruce

You would want to convert TAB <9> to a space and not just remove it. Same for Hard Space.

I would also reiterate IMO it’s good to remove any mix of white space 9,13,10,32 off the end of a TEXT on accepted. You might also want to remove it off the front.

cunningly, there’s a StringTheory method for that; Trim
https://www.capesoft.com/docs/StringTheory3/StringTheory.htm#Trim
as in
st.Trim(‘<13,10,32,9,0,255>’)