Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

need a code bit

31 views
Skip to first unread message

Gandalf Parker

unread,
Aug 25, 2012, 8:46:42 AM8/25/12
to
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.

Thanks
Gandalf Parker
--
Actually I rather prefer my Basic to be basic.
That might seem obvious but you would be amazed how difficult its getting.

Auric__

unread,
Aug 25, 2012, 1:02:35 PM8/25/12
to
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.)

--
You knew this job was dangerous when you took it!

(Good sigmonster. Have a cookie.)

Gandalf Parker

unread,
Aug 26, 2012, 9:39:52 AM8/26/12
to
"Auric__" <not.m...@email.address> contributed wisdom to
news:XnsA0BA662985320au...@88.198.244.100:

>
> 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.)
>

Thank you very much.

This is part of a long hard road but I am hoping to benefit from it.

It goes kindof like this...
iTunes Playlist
export to XML
parse XML
for each song in playlist
create one http link to Amazon with my Affiliate code
end

The result should be a webpage for each of my popular lists on some hard
to find musical subjects. People can click, listen to a bit of it, maybe
buy it. And if they do they I get a couple pennies for each purchase off
my links.

Originally I was going to use the ID codes that are in each iTunes entry
when you buy from Amazon but apparently those shift. So it seems that a
better way is to turn each line into an amazon search for the song and
the author.

Eventually I want to be able to happily just keep adding to my playlists.
Parodies, Covers, Mashups, Halloween, WTF, and Waltzes you didnt know
were Waltzes (very popular with people searching for personally perfect
wedding or quincenera songs). Every once in awhile I will just run the
playlist thru the program to get a new uptodate webpage to refer people
to.

And beyond that, maybe even a monster version. I use iTunes Smart
Playlists to maintain the lists by putting one-word tags in the comments
field. A song might be cover halloween waltz or might be parody WTF
political. So a monster program might process the ENTIRE iTuens database
in XML form and not only build a search string for each song but then
parse the comments string to write that search string to each applicable
.html file so that all of them are updated in one run. MUHAhahahahaha

Its not that I dont want to make money. I just dont want to work hard
doing it.


Gandalf Parker

Auric__

unread,
Aug 26, 2012, 12:23:57 PM8/26/12
to
Something like this, I suppose?

list_page = freefile
open "the_big_list.html" for output as #list_page
for each file_entry in list
fix name as appropriate
build link_text$
output link_text$ to #list_page
for each tag in file_entry
if tag is not in tags()
redim preserve tags(ubound(tags)+1)
redim preserve tag_files(ubound(tags))
tags(ubound(tags)) = tag
tag_files(ubound(tags)) = freefile
open tag + ".html" for output as tag_files(ubound(tags))
end if
output link_text$ to #tag_files(tag)
next
next

(Personally, I'd do it in FreeBASIC, but that's just what I'm used to. I
imagine that YaBasic can probably do it just fine.)

> Its not that I dont want to make money. I just dont want to work hard
> doing it.

Perhaps you've heard of Heinlein's "The Tale of the Man Who Was Too Lazy
to Fail"?

--
There is an evil in my heart, I have always known this and I spoke of it
to you. Hate and anger, twisted and black... and I... I cannot control it.

Gandalf Parker

unread,
Aug 28, 2012, 8:04:06 AM8/28/12
to
"Auric__" <not.m...@email.address> contributed wisdom to
news:XnsA0BB5F9D6A548au...@88.198.244.100:

> (Personally, I'd do it in FreeBASIC, but that's just what I'm used to. I
> imagine that YaBasic can probably do it just fine.)

I have looked at the many MANY BASICs. Im an old old Internet Native. I ran
official servers for Internet since before it was called Internet. Military
then Commercial.

My choice was based on what I would want from any programming platform:
it was included in the catalog of my personal Internet servers OS (Debian
Linux) as an official part of the OS package. So it was part of the
automatic maintained and updated packages. Altho YaBasic itself no longer
seems to be maintaining that distinction :(

It appeared to be compliant with the ANSI Standard for BASICs. Altho it no
longer seems to be making a major effort to stay that way.

It was cross-compatable to all of the other OSs I use so it was at least
basically portable between my desktop playground and my ISP server.

But more and more it seems that I may have to revisit that subject.

>> Its not that I dont want to make money. I just dont want to work hard
>> doing it.
>
> Perhaps you've heard of Heinlein's "The Tale of the Man Who Was Too Lazy
> to Fail"?

I am embarrased to say that it did not ring any bells but on googling it
and reading highlights it appears that it defintely should go on my
wishlist. I am 56 and have been happily retired for quite awhile. That
story seems to have many amazing similarities to my life. :)


Gandalf Parker


ArarghMai...@not.at.arargh.com

unread,
Sep 2, 2012, 1:31:41 AM9/2/12
to
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.

ne...@rtrussell.co.uk

unread,
Sep 2, 2012, 5:09:47 AM9/2/12
to
On Sep 2, 6:31 am, ArarghMail208NOS...@NOT.AT.Arargh.com wrote:
> If I were to code that routine in MS basic, it would look somewhat
> like:
>
>    FOR N=1 TO LEN(what$)
>       if mid$(what$,n,1)=lookfor$ then mid$(what$,n,1)=replacewith$
>    next n

Using a FOR...NEXT loop is likely to be slow compared with using
INSTR, especially if there are only a few occurrences of lookfor$ in
what$. This is how I would code it in BBC BASIC:

REPEAT
n% = INSTR(what$,lookfor$)
IF n% THEN MID$(what$,n%,1) = replacewith$
UNTIL n%=0

There's no iteration at all if what$ doesn't contain lookfor$.

Richard.
http://www.rtrussell.co.uk/

Gandalf Parker

unread,
Sep 2, 2012, 10:09:55 AM9/2/12
to
"ne...@rtrussell.co.uk" <ne...@rtrussell.co.uk> contributed wisdom to
news:6c5b4ea8-a6ec-4ad9...@z17g2000yqk.googlegroups.com:

> On Sep 2, 6:31�am, ArarghMail208NOS...@NOT.AT.Arargh.com wrote:

I appreciate more examples. Thank you both.

If I was interested in speed I wouldnt be in BASIC at all. I like BASIC
because its readable english. More and more that is important because when
I read my own old code Im impressed with it. I do not remember writing
anything so elegant and I am forced to trace thru it as if it was someone
elses code to make a change.

So I prefer understanding over speed. I dont care if it runs all night as
long as I can easily understand it. :) I always thought that was almost the
definition of BASIC.
But I love seeing other examples for the same thing. Thanks.

Gandalf Parker

ArarghMai...@not.at.arargh.com

unread,
Sep 4, 2012, 2:43:26 PM9/4/12
to
On Sun, 2 Sep 2012 02:09:47 -0700 (PDT), "ne...@rtrussell.co.uk"
<ne...@rtrussell.co.uk> wrote:

>On Sep 2, 6:31�am, ArarghMail208NOS...@NOT.AT.Arargh.com wrote:
>> If I were to code that routine in MS basic, it would look somewhat
>> like:
>>
>> � �FOR N=1 TO LEN(what$)
>> � � � if mid$(what$,n,1)=lookfor$ then mid$(what$,n,1)=replacewith$
>> � �next n
>
>Using a FOR...NEXT loop is likely to be slow compared with using
>INSTR, especially if there are only a few occurrences of lookfor$ in
>what$.
True - didn't think of that.

Just checked the old ASM routine, and that basically how it was done
- the routine after the regs are set up:

LoopHere:
repne scasb es:[di] ; look for it
jne @f
mov es:[di]-1,ah
@@: jcxz Exit ; any string left?
jmp LoopHere ; yep - look some more
Exit: ret

And in MS's basics: have to use DO & LOOP in place of REPEAT & UNTIL

>This is how I would code it in BBC BASIC:
>
> REPEAT
> n% = INSTR(what$,lookfor$)
> IF n% THEN MID$(what$,n%,1) = replacewith$
> UNTIL n%=0
>
>There's no iteration at all if what$ doesn't contain lookfor$.

ne...@rtrussell.co.uk

unread,
Sep 7, 2012, 7:01:04 AM9/7/12
to
On Sep 2, 3:09 pm, Gandalf Parker
<gand...@the.dead.ISP.of.Community.net> wrote:
> I dont care if it runs all night as long as I can easily understand it. :)

I would say that's untypical. Most of my BASIC programs are speed-
sensitive to some degree, so when there is a straightforward way to
increase the speed without significantly impairing the readability I
will use it.

Richard.
http://www.rtrussell.co.uk/

Ben Yates

unread,
Sep 7, 2012, 6:29:10 PM9/7/12
to
I know what he means. I'd let my old TI chug out something overnight. Sometimes stuck something in the keyboard so when it came to a prompt it would keep going.

About 10% of the time I'd wake up to a screeching noise telling me it had locked up.

I worked at a business that sold mailing lists. One of their LARGE Basic programs, in GW-Basic, cleaned up mailing lists... changing case, adding/removing punctuation, and gender-guessing to add titles.

We'd run these overnight...

I was young and stupid. I was the night "Systems Administrator". Meaning I got to take the garbage out, literally.

And run these programs...

But then I brought in a copy of QuickBasic Compiler... and the job went away. I got stuck for a couple of months on day shift, feeding the envelopes to the printers, stuffing envelopes, and then got let go...

This is back around 1989...

ne...@rtrussell.co.uk

unread,
Sep 9, 2012, 1:37:02 PM9/9/12
to
On Sep 7, 11:29 pm, Ben Yates <winston19842...@yahoo.com> wrote:
> I'd let my old TI chug out something overnight.

I'm familiar with that. When I'm doing Colour Recovery processing
it's common for me to run five copies of the application at once (to
make maximum use of the number of cores, and so one instance can be
using the CPU whilst another is waiting for data from the disk) and
then leave the PC to crunch the data overnight:

http://colourrecovery.wikispaces.com/

But that's got nothing to do with using a slow language. The program
is written in BBC BASIC but the time-critical parts are all MMX/SSE
assembler, hand-optimsed to run as fast as I can possibly manage!
It's unavoidably a highly computation-intensive operation.

Richard.
http://www.rtrussell.co.uk/
0 new messages