dbTalk Databases Forums  

Re: Purge funny characters

comp.databases.pick comp.databases.pick


Discuss Re: Purge funny characters in the comp.databases.pick forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Richard Wilson
 
Posts: n/a

Default Re: Purge funny characters - 02-27-2007 , 04:46 AM






depends on your version of pick

SPACES = STR(' ',LEN(FUNNYCHARS))
CONVERT FUNNYCHARS TO SPACES IN NAME
NAME = TRIM(NAME)

NOTE: you may not even need to use the SPACES logic try
CONVERT FUNNYCHARS TO '' IN NAME

Rich

diets wrote:
Quote:
Hi all

I need to remove funny characters from a string, and presently do it
as follows:

NAME = 'THIS IS THE STRING WITH )(*&*& THE FUNNY && CHARACTERS @#
IN IT'
FUNNYCHARS = '!`~@#$%^&*()_-+={[}]|\"' : "':;<,>.?/"
FOR CHARS = 1 TO LEN(FUNNYCHARS)
FC = FUNNYCHARS[CHARS,1]
CONVERT FC TO ' ' IN NAME
NEXT VAL
NAME = TRIM(NAME)

Is there a way to do It more efficiently?

Any comment will be appreciated

Diets



Reply With Quote
  #2  
Old   
GVP
 
Posts: n/a

Default Re: Purge funny characters - 02-27-2007 , 05:23 AM






CONVERT FUNNYCHARS TO "" IN NAME
*NAME = TRIM(NAME)

Regards,

Grigory


Reply With Quote
  #3  
Old   
Allen Egerton
 
Posts: n/a

Default Re: Purge funny characters - 02-27-2007 , 07:34 AM



diets wrote:
Quote:
Hi all

I need to remove funny characters from a string, and presently do it
as follows:

NAME = 'THIS IS THE STRING WITH )(*&*& THE FUNNY && CHARACTERS @#
IN IT'
FUNNYCHARS = '!`~@#$%^&*()_-+={[}]|\"' : "':;<,>.?/"
FOR CHARS = 1 TO LEN(FUNNYCHARS)
FC = FUNNYCHARS[CHARS,1]
CONVERT FC TO ' ' IN NAME
NEXT VAL
NAME = TRIM(NAME)

Is there a way to do It more efficiently?

Any comment will be appreciated

Diets

Perhaps instead of trying to define all "funny" characters, you'd be
better off served by defining all "good" characters.

I can't test the following code, (the machine I'm on right now doesn't
have Pick/Universe/etc), but it should be pretty close to compilable.

* Initialization
GOOD.CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
GOOD.CHARS := 'abcdefghijklmnopqrstuvwxyz'
GOOD.CHARS := '0123456789'
GOOD.CHARS := " " ;* Space

* Get/define string to clean up.
NAME = 'THIS IS THE STRING WITH )(*&*& THE FUNNY && CHARACTERS @#IN IT'

* Clean it.
TEMP.BAD.CHARS = NAME
CONVERT GOOD.CHARS TO "" IN TEMP.BAD.CHARS
IF (TEMP.BAD.CHARS) THEN
CONVERT TEMP.BAD.CHARS TO "" IN NAME
END
*
NAME = TRIM(NAME) ;* Space legit; multiple spaces aren't.

--
Allen Egerton
aegerton at pobox dot com


Reply With Quote
  #4  
Old   
Scott Ballinger
 
Posts: n/a

Default Re: Purge funny characters - 02-27-2007 , 08:53 AM



How about:

subroutine clean.sub(string)
* remove bad characters from a string/record/whatever
bad.chars = ""
for n = 1 to 31
bad.chars := char(n)
next n
for n = 128 to 250
bad.chars := char(n)
next n
convert bad.chars to "" in string
return


/Scott Ballinger
Pareto Corporation
Edmonds WA USA
206 8713 6006


Reply With Quote
  #5  
Old   
Ed Sheehan
 
Posts: n/a

Default Re: Purge funny characters - 02-27-2007 , 02:16 PM



Not next to a box at the moment, but experiment with:

NAME = OCONV(NAME,'MCAN')

That'll return letters and numbers. May munge spaces tho...

Ed

"diets" <diets (AT) homemail (DOT) co.za> wrote

Quote:
Hi all

I need to remove funny characters from a string, and presently do it
as follows:

NAME = 'THIS IS THE STRING WITH )(*&*& THE FUNNY && CHARACTERS @#
IN IT'
FUNNYCHARS = '!`~@#$%^&*()_-+={[}]|\"' : "':;<,>.?/"
FOR CHARS = 1 TO LEN(FUNNYCHARS)
FC = FUNNYCHARS[CHARS,1]
CONVERT FC TO ' ' IN NAME
NEXT VAL
NAME = TRIM(NAME)

Is there a way to do It more efficiently?

Any comment will be appreciated

Diets




Reply With Quote
  #6  
Old   
Mike Preece
 
Posts: n/a

Default Re: Purge funny characters - 02-27-2007 , 05:27 PM



On Feb 27, 10:40 am, "diets" <d... (AT) homemail (DOT) co.za> wrote:
Quote:
Hi all

I need to remove funny characters from a string, and presently do it
as follows:

NAME = 'THIS IS THE STRING WITH )(*&*& THE FUNNY && CHARACTERS @#
IN IT'
FUNNYCHARS = '!`~@#$%^&*()_-+={[}]|\"' : "':;<,>.?/"
FOR CHARS = 1 TO LEN(FUNNYCHARS)
FC = FUNNYCHARS[CHARS,1]
CONVERT FC TO ' ' IN NAME
NEXT VAL
NAME = TRIM(NAME)

Is there a way to do It more efficiently?

Any comment will be appreciated

Diets
Alcohol is a toxin!



Reply With Quote
  #7  
Old   
Cliff
 
Posts: n/a

Default Re: Purge funny characters - 02-28-2007 , 04:20 PM



On Feb 27, 5:40 am, "diets" <d... (AT) homemail (DOT) co.za> wrote:
Quote:
Hi all

I need to remove funny characters from a string, and presently do it
as follows:

NAME = 'THIS IS THE STRING WITH )(*&*& THE FUNNY && CHARACTERS @#
IN IT'
FUNNYCHARS = '!`~@#$%^&*()_-+={[}]|\"' : "':;<,>.?/"
FOR CHARS = 1 TO LEN(FUNNYCHARS)
FC = FUNNYCHARS[CHARS,1]
CONVERT FC TO ' ' IN NAME
NEXT VAL
NAME = TRIM(NAME)

Is there a way to do It more efficiently?

Any comment will be appreciated

Diets
This looks at the string delimited substrings instead of each
character

NEW.NAME = ''
FOR X = 1 TO DCOUNT(NAME,' ')
STR = OCONV(FIELD(NAME,' ',X),'MCAN')
NEW.NAME = NEW.NAME:' ':STR
NEXT X
NEW.NAME = TRIM(NEW.NAME)
CRT NEW.NAME

Cliff



Reply With Quote
  #8  
Old   
art
 
Posts: n/a

Default Re: Purge funny characters - 02-28-2007 , 04:25 PM



diets wrote:
Quote:
Hi all

I need to remove funny characters from a string, and presently do it
Take a look at OCONV(FUNNY.CHARS,'MCP')

Art


Reply With Quote
  #9  
Old   
Chandru Murthi
 
Posts: n/a

Default Re: Purge funny characters - 03-17-2007 , 10:22 AM



Just curious: you have CONVERT(NAME, GOOD.CHARS, '') to convert all
good.chars to nulls. Which system has this syntax, because on UV its:
CONVERT(GOOD.CHARS, '',NAME)?

I won't ask why you're replace "good" characters with nulls to eliminate
them

Chandru
"Terry Layne" <usenet (AT) laynesoftware (DOT) com> wrote

Quote:
On Tue, 27 Feb 2007 13:34:38 +0000, Allen Egerton wrote:

diets wrote:
Hi all

I need to remove funny characters from a string, and presently do it
as follows:
[snip]

* Initialization
GOOD.CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
GOOD.CHARS := 'abcdefghijklmnopqrstuvwxyz'
GOOD.CHARS := '0123456789'
GOOD.CHARS := " " ;* Space

* Get/define string to clean up.
NAME = 'THIS IS THE STRING WITH )(*&*& THE FUNNY && CHARACTERS @#IN IT'

[snip]

After you get GOOD.CHARS you can do

NAME = TRIM(CONVERT(NAME, CONVERT(NAME, GOOD.CHARS, ''), ''))


--
Terry Layne
Portland, OR




Reply With Quote
  #10  
Old   
Chandru Murthi
 
Posts: n/a

Default Re: Purge funny characters - 03-19-2007 , 09:23 AM



Wow, tricky, didn't notice that! Eliminates controls as well.

Wonder if jbase has a switch to reverse that syntax to the uv form?

Chandru

"Terry Layne" <usenet (AT) laynesoftware (DOT) com> wrote

Quote:
jBASE uses that syntax. The inner CONVERT leaves you with bad chars and
the outer CONVERT eliminates them.

-Terry

On Sat, 17 Mar 2007 16:22:41 +0000, Chandru Murthi wrote:

Just curious: you have CONVERT(NAME, GOOD.CHARS, '') to convert all
good.chars to nulls. Which system has this syntax, because on UV its:
CONVERT(GOOD.CHARS, '',NAME)?

I won't ask why you're replace "good" characters with nulls to eliminate
them

Chandru
"Terry Layne" <usenet (AT) laynesoftware (DOT) com> wrote in message
newsan.2007.03.17.03.32.51.18599 (AT) laynesoftware (DOT) com...
On Tue, 27 Feb 2007 13:34:38 +0000, Allen Egerton wrote:

diets wrote:
Hi all

I need to remove funny characters from a string, and presently do it
as follows:
[snip]

* Initialization
GOOD.CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
GOOD.CHARS := 'abcdefghijklmnopqrstuvwxyz'
GOOD.CHARS := '0123456789'
GOOD.CHARS := " " ;* Space

* Get/define string to clean up.
NAME = 'THIS IS THE STRING WITH )(*&*& THE FUNNY && CHARACTERS @#IN
IT'

[snip]

After you get GOOD.CHARS you can do

NAME = TRIM(CONVERT(NAME, CONVERT(NAME, GOOD.CHARS, ''), ''))


--
Terry Layne
Portland, OR


--
Terry Layne
Portland, OR




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.