LB Booster
« word$(x$,3) = y$ »

Welcome Guest. Please Login or Register.
Nov 24th, 2017, 7:28pm


Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
LB Umbrella forum
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: word$(x$,3) = y$  (Read 157 times)
Alincon
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 143
xx word$(x$,3) = y$
« Thread started on: Apr 1st, 2017, 8:03pm »

LBB allows mid$ on the left side of the equal sign, why not word$?
I would like to do this:

Code:
someRec$ = "name|address|sequence|etc|etc"
seq$ = word$(someRec$,3,"|")
seq = val(seq$)
seq = seq + 1
word$(someRec$,3,"|") = str$(seq)
 


r.m.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1279
xx Re: word$(x$,3) = y$
« Reply #1 on: Apr 1st, 2017, 10:04pm »

on Apr 1st, 2017, 8:03pm, Alincon wrote:
LBB allows mid$ on the left side of the equal sign, why not word$?

They're really quite different. The crucial thing about assigning to a sub-string is that it's an 'in place' substitution: the length of the string doesn't change, all that happens is that a subset of characters are replaced.

Doing something similar with word$, as you suggest, isn't a straightforward substitution, because (presumably) the 'new' sub-string may be a different length from the 'old' sub-string. For example, in the case of the code you listed, you may wish to replace "99" with "100".

That might mean allocating a new memory block, to accommodate the increased length, copying the old string into it (moving the 'tail' section along one to open up the extra space) and then replacing the "99" with "100".

Hopefully you can see that this is an entirely different kind of operation than a simple assignment to a sub-string. If you accepted a restriction that the new sub-string must be the same length as the old sub-string then it would be possible, but that would be quite limiting.

Richard.
User IP Logged

RobM
Junior Member
ImageImage


member is offline

Avatar




PM


Posts: 87
xx Re: word$(x$,3) = y$
« Reply #2 on: Apr 2nd, 2017, 12:53am »

Quote:
I would like to do this:


Code:
    someRec$ = "name|address|99|etc|etc"
    seq$ = word$(someRec$,3,"|")
    seq = val(seq$)
    seq = seq + 1
    print someRec$
    print ReplaceWord$(someRec$,3,"|",str$(seq))
    end

function ReplaceWord$(source$,index,separator$,new$)
    length=len(source$)
    for x=1 to length
    if mid$(source$,x,1)=separator$ then count=count+1
    next x
    dim temp$(count+1)
    for x=1 to count+1
      temp$(x)=word$(source$,x,separator$)
    next x
    temp$(index)=new$
    for x=1 to count+1
       if x=count+1 then separator$=""
       ReplaceWord$=ReplaceWord$+temp$(x)+separator$
    next x
end function 

« Last Edit: Apr 2nd, 2017, 03:33am by RobM » User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Donate $6.99 for 50,000 Ad-Free Pageviews!


This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls