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.
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
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.
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.