Page 1 of 1

Removing non-alphanumeric characters using Convert function

Posted: Tue May 01, 2007 2:22 pm
by abc123
I am trying to remove all non-alphanumeric characters from a string. Two questions:
1)How do you do:

Convert("""", MyString)?
This does not compile. Gives a validation error.

2)Is there any way to do it in PX without writing a routine? I went through all the posts here but I don't see a PX solution.

Posted: Tue May 01, 2007 2:40 pm
by DSguru2B
Convert() requires three arguments.
Try something like

Code: Select all

Convert("~!@#$%^&*()_+=-`,./;[]\|}{:?>< ", "", in.Col)
That should be close.

Posted: Tue May 01, 2007 3:00 pm
by abc123
DSGuru2B, thank you for your response. Yes, I am aware that Convert requires 3 arguments. I made a mistake in my first post. I was already doing the exact same thing that you posted. The error happens because of the 2 double quotes.

If I put in a double quote as follows:

Convert("~!@#$%^&*()_+=-`,./;[]\|}{:?>< "", "", MyString)

it gives a validation error. I tried putting in 2 double quotes together so that the compiler translates into one but it also gives the same validation error.

Also, I was looking for a solution that would also take care of all non-alphanumeric characters including non-printable characters.

Posted: Tue May 01, 2007 3:15 pm
by ray.wurlod
There are three quote characters available. Surround the string with one of the others. Concatenate if you must.

Code: Select all

Convert('"':"'", "", InLink.TheString)
The first piece is a double quote character surrounded by single quote characters, the second piece is a single quote character surrounded by double quote characters.

Posted: Tue May 01, 2007 4:21 pm
by abc123
Thanks Ray. It worked. Can you tell me if there is a way in PX jobs to only keep alphanumeric characters and strip everything else including non-printable characters without using a routine and Ascii codes?

Posted: Tue May 01, 2007 6:21 pm
by DSguru2B
The Convert() function will work to retain only alphanumeric characters. But for non-printable characters, I think you will have to go the routine route.

Posted: Tue May 01, 2007 7:05 pm
by ray.wurlod
You will need a routine or a BASIC Transformer stage.

Posted: Wed May 02, 2007 1:47 pm
by ady
ray.wurlod wrote:You will need a routine or a BASIC Transformer stage.
Ray , How can we do it in basic transformer without a routine ?

Posted: Thu May 03, 2007 6:05 am
by JoshGeorge
Try this: Put an external filter and use unix command in your job to strip non alphanumeric characters

Posted: Thu May 03, 2007 6:50 am
by DSguru2B
ady wrote: Ray , How can we do it in basic transformer without a routine ?
Use OCONV/ICONV with MCP format to convert all nonprintable characters to a dot. Then use the above convert statement to extract only alphabets and numers.