ernie
New Member
Posts: 44
|
Post by ernie on Feb 16, 2021 10:34:00 GMT -5
Using Liberty Basic Pro v. 4.51 the code below results in an endless loop:
a$ = "2 packs cigarettes" b$ = replstr$(a$, "packs", "packs of") print b$
|
|
|
Post by tenochtitlanuk on Feb 16, 2021 11:19:32 GMT -5
It also throws the debugger.... try single-stepping through it.
|
|
|
Post by pierre on Feb 16, 2021 12:04:26 GMT -5
The new string must not contain exactly the same word as the old string.
Replacing "packs" with "packs of"' does not work. But "PACKS of" works fine, and so does "packets of".
EDIT:
the solution was already published on this forum, by sarossell I believe. You have to use an intermediate variable, for example as follows:
a$ = "2 packs cigarettes" old$ = "packs" new$ = "packs of" print strRep$(a$, old$, new$) function strRep$(a$,old$,new$) dummy$ = chr$(0) strRep$ = replstr$(replstr$(a$,old$,dummy$),dummy$,new$) end function
pierre
|
|
|
Post by Brandon Parker on Feb 20, 2021 21:05:22 GMT -5
|
|
ernie
New Member
Posts: 44
|
Post by ernie on Mar 14, 2021 0:40:29 GMT -5
Thanks Brandon.
|
|