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

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 03:28am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
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
BBC BASIC Home Page
Liberty BASIC forum (the original)

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


member is offline

Avatar




PM


Posts: 147
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: 1348
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: 91
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 »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls