Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.basic.misc > #315

Re: need a code bit

From ArarghMail208NOSPAM@NOT.AT.Arargh.com
Newsgroups comp.lang.basic.misc
Subject Re: need a code bit
Date 2012-09-02 00:31 -0500
Organization Ripco Communications Inc.
Message-ID <u2r5489qapdoqvqdk9vilrhfdjh9napph5@4ax.com> (permalink)
References <XnsA0BA3AC6BDBB0gandalfparker@88.198.244.100> <XnsA0BA662985320auricauricauricauric@88.198.244.100>

Show all headers | View raw


On Sat, 25 Aug 2012 17:02:35 +0000 (UTC), "Auric__"
<not.my.real@email.address> wrote:

>Gandalf  Parker wrote:
>
>> I need a code bit just to kick me in the ass. A major project of mine
>> seems all ironed out in my head but Im hitting a wall. I KNOW I used to
>> do this with no trouble at all.
>>
>> You are going to laugh....
>>
>> For some reason I am blocked on a simple routine to modify a string.
>> some words like this need to become some+words+like+this.
>> Simple replace space with +
>>
>> The language is YaBasic on Debian Linux but any old-code replace routine
>> should work.
>
>Welcome to the dark side. ;-)
>
>I'm not terribly familiar with YaBasic so there may or may not be better 
>ways to do this [shrug] but this works:
>
>  SUB REPLACE$(what$, lookfor$, replacewith$)
>    LOCAL n
>    DO
>      n = INSTR(what$, lookfor$)
>      IF n THEN
>        what$ = LEFT$(what$, n-1) + replacewith$ + MID$(what$, n+1)
>      ELSE
>        BREAK
>      END IF
>    LOOP
>    RETURN what$
>  END SUB
>
>Use it like this:
>  x$ = REPLACE$("some words like this", " ", "+")
>
>(I had a hell of a time getting this to work as a function, for no obvious 
>reason. YaBasic doesn't like me, I guess.)

Some time back, 20 years ago actually,I wrote an asm routine to do
just that!

ReplaceChar String$, 32, 43 

Passing integers was faster and cheaper than passing strings in MS
Basics which was important when running on a 10Mhz 286.  :-)

If I were to code that routine in MS basic, it would look somewhat
like:

SUB REPLACE$(what$, lookfor$, replacewith$)

dim n

   FOR N=1 TO LEN(what$)
      if mid$(what$,n,1)=lookfor$ then mid$(what$,n,1)=replacewith$
   next n

end sub
-- 
ArarghMail208 at [drop the 'http://www.' from ->] http://www.arargh.com
BCET Basic Compiler Page: http://www.arargh.com/basic/index.html

To reply by email, remove the extra stuff from the reply address.

Back to comp.lang.basic.misc | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

need a code bit Gandalf  Parker <gandalf@the.dead.ISP.of.Community.net> - 2012-08-25 12:46 +0000
  Re: need a code bit "Auric__" <not.my.real@email.address> - 2012-08-25 17:02 +0000
    Re: need a code bit Gandalf  Parker <gandalf@the.dead.ISP.of.Community.net> - 2012-08-26 13:39 +0000
      Re: need a code bit "Auric__" <not.my.real@email.address> - 2012-08-26 16:23 +0000
        Re: need a code bit Gandalf  Parker <gandalf@the.dead.ISP.of.Community.net> - 2012-08-28 12:04 +0000
    Re: need a code bit ArarghMail208NOSPAM@NOT.AT.Arargh.com - 2012-09-02 00:31 -0500
      Re: need a code bit "news@rtrussell.co.uk" <news@rtrussell.co.uk> - 2012-09-02 02:09 -0700
        Re: need a code bit Gandalf  Parker <gandalf@the.dead.ISP.of.Community.net> - 2012-09-02 14:09 +0000
          Re: need a code bit "news@rtrussell.co.uk" <news@rtrussell.co.uk> - 2012-09-07 04:01 -0700
            Re: need a code bit Ben Yates <winston19842005@yahoo.com> - 2012-09-07 15:29 -0700
              Re: need a code bit "news@rtrussell.co.uk" <news@rtrussell.co.uk> - 2012-09-09 10:37 -0700
        Re: need a code bit ArarghMail208NOSPAM@NOT.AT.Arargh.com - 2012-09-04 13:43 -0500

csiph-web