[Date Prev][Date Next][Thread Prev][Thread Next]
[Author Index] [Date Index] [Thread Index]
[SQR-USERS Info] [SQRUG Home Page]

Re: Is there a replace command or equivilent in SQR



Hi,

I wrote a procedure to do this throughout a string.

Arguments:
find_str - character(s) to be look for in string
replace_str - characters(s) that will replace the find_str
str - string to have characters be replaced (this is returned)


example:
$string      = 'I LOVE SQR'
$replace_str = '+'
$find_str    = chr(32) !space

do replace-char-in-string($find_str, $replace_str, $string)
show $string

I+LOVE+SQR

Pam


!****************************************************
!REPLACE_CHAR_IN_STR: Pass in string and find str and
!replace string
!This procedure finds all occurences of find string and
!substitutes the replace string
!****************************************************
begin-procedure Replace-Char-In-String ($find_str, $replace_str, :$str)

  let #i    = 1
  let #slen = length(rtrim($str, ' '))
  let $nstr = ''

  while (#i <= #slen)
    let $char = substr($str,#i,1)
    if $char = $find_str
      let $char = $replace_str
    end-if
    let $nstr = $nstr || $char
    add 1 to #i
  end-while

  let $str = $nstr

end-procedure Replace-Char-In-String




 -----Original Message-----
From:   John McNall [mailto:jmcnall@TGTSOLUTIONS.COM]
Sent:   Tuesday, March 06, 2001 10:09 AM
To:     SQR-USERS@LIST.IEX.NET
Subject:        Is there a replace command or equivilent in SQR

Hello all,

It seams to me that I recall a command in SQR that will read a string,
looking for a designated character and allow you to replace it.
For example when you receive data from an HTML form spaces are replaced by a
'+'
Thus you may end up with "I+am+wanting+to+replace+the+plus+signs"
Does anyone know of such a command or am I once again wishful thinking?
Thanks in advance.

John