Complement to replace$

Give it a try, it costs you nothing !
Post Reply
User avatar
Fernando Perez
Posts: 378
Joined: Mon Feb 15, 2021 10:09 pm
Location: Santander (Spain)
Has thanked: 195 times
Been thanked: 265 times

Complement to replace$

Post by Fernando Perez »

I frequently use Annex's replace$ command, but I find it useful to replace a piece of a string, defined by its starting position and length, with another given string.
Something similar to the way of using mid$ in qBasic as a function or as a sub.
I propose to implement something similar to this in Annex, perhaps with another name to avoid confusion:

Code: [Local Link Removed for Guests]

a$ = "It is a period of civil wars in the galaxy"
wlog a$
replace a$, 19, 10, "great joy"
wlog a$

END

SUB replace(t$, start, long, x$)
  t$ = left$(t$, start-1) + x$ + mid$(t$, start + long)
END SUB  
  
User avatar
cicciocb
Site Admin
Posts: 1841
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 397 times
Been thanked: 1232 times
Contact:

Re: Complement to replace$

Post by cicciocb »

HI Fernando,
yes, I can simply implement the MID$ as a command
MID$(b$, x,y) = "lklk"

I remember I did that for the espbasic some years ago :lol:
User avatar
Fernando Perez
Posts: 378
Joined: Mon Feb 15, 2021 10:09 pm
Location: Santander (Spain)
Has thanked: 195 times
Been thanked: 265 times

Re: Complement to replace$

Post by Fernando Perez »

I remember that in QBasic it was like you say.
That would be getting closer and closer to the origins.
It would seem perfect to me, but what do others think?
bugs
Posts: 142
Joined: Mon Feb 08, 2021 10:10 pm
Location: Scotland
Has thanked: 43 times
Been thanked: 49 times

Re: Complement to replace$

Post by bugs »

I like it - if it is not too much effort to add it to the string functions.
BeanieBots
Posts: 313
Joined: Tue Jun 21, 2022 2:17 pm
Location: South coast UK
Has thanked: 165 times
Been thanked: 101 times

Re: Complement to replace$

Post by BeanieBots »

Mid$ as a command would be very useful.
Post Reply