Paul,

You might consider using the following simpler and faster code

SET VAR vnospaces = (SRPL(.vinpstring,' ',NULL,0)) -- remove all blanks
SET VAR vnbrchar = (SLEN(.vnospaces))

WHILE vnbrchar > 0 THEN
 SET VAR vcurchar = (SGET(.vnospaces,1,.vnbrchar))

 IF (ISALPHA(.vcurchar)) = 0 AND (ISDIGIT(.vcurchar)) = 0 THEN
  SET VAR vnospaces = (SMOVE('_',1,1,.vnospaces,.vnbrchar))
 ENDIF

 SET VAR vnbrchar = .vnbrchar - 1
ENDWHILE
RETURN


 Jim Bentley
American Celiac Society
[email protected]
tel: 1-504-737-3293




________________________________
From: Jason Kramer <[email protected]>
To: RBASE-L Mailing List <[email protected]>
Sent: Wed, November 18, 2009 8:16:09 AM
Subject: [RBASE-L] - Re: Brain Freeze on Stripping Spaces and Characters froma 
String

 I had to do something similar a while back.  I have modified my
solution and pasted it below.  Please let me know what you think.

SET VAR voristring TEXT = 'Test with spaces and non-alphanum
characters: $...@.'

SET VAR vstrlen INTEGER = NULL
SET VAR vcurpos INTEGER = 1
SET VAR vcurchar TEXT = NULL
SET VAR vnospaces TEXT = NULL
SET VAR vnewstring TEXT = NULL

PAUSE 2 USING .voristring CAPTION 'Before'

SET VAR vnospaces = (SRPL(.voristring,' ', '',0))
SET VAR vstrlen = (SLEN(.vnospaces))

WHILE vcurpos <= .vstrlen THEN
  SET VAR vcurchar = (SGET(.vnospaces,1,.vcurpos))

  IF (ISALPHA(.vcurchar)) = 0 AND (ISDIGIT(.vcurchar)) = 0 THEN
    IF vcurpos = 1 THEN
      SET VAR vnewstring = '_'
    ELSE
      SET VAR vnewstring = .vnewstring + '_'
    ENDIF
  ELSE
    IF vcurpos = 1 THEN
      SET VAR vnewstring = .vcurchar
    ELSE
      SET VAR vnewstring = .vnewstring + .vcurchar
    ENDIF
  ENDIF

  SET VAR vcurpos = .vcurpos + 1
ENDWHILE

PAUSE 2 USING .vnewstring CAPTION 'After'

CLEAR VARIABLES voristring, vstrlen, vcurpos, vcurchar, vnospaces,
vnewstring

RETURN

Jason Kramer
University Archives and Records Management
002 Pearson Hall
(302) 831 - 3127 (voice)
(302) 831 - 6903 (fax)

Paul Buckley wrote: 
I know I'm missing something simple, probably not enough caffeine today.
>I'm trying to setup a computed column in a table that will strip all spaces
>from the string and replace all the non-alpha or numeric characters with an
>underscore (_).  Here's some examples; First & Third would become
>First_Third, First/Third would become First_Third and Item # would become
>Item_.
>
>Can someone suggest a way to do this please.  Thanks in advance.
>
>Paul Buckley
>
>
>


      

Reply via email to