deepening listed subscripting

new topic     » topic index » view thread      » older message » newer message

Antonio Alessi wrote:
> 
> ags wrote:
> > 
> > Antonio Alessi wrote:
> > > An expression like:
> > > }}}
<eucode>
> > > newString­ =
> > > originalString[1..2]&"INSERT"&originalString[5..9]&originalString[27..$]
> > > </eucode>
{{{

> > > could simply become:
> > > }}}
<eucode>
> > > newString­ = originalString[1..2]&"INSERT"&[5..9]&[27..$]
> > > </eucode>
{{{

> > > It should be plain to implement, I mean more useful than complicated...
> > 
> > I don't think that would work very well.  What if you wanted to use multiple
> > strings like:
> > 
> > }}}
<eucode>
> > newString = originalString[1..2] & "INSERT" & otherString[3..5] & [5..9]
> > </eucode>
{{{

> > What would the "[5..9]" refer to?
> 
> Hi Gary,
> 
> The last declared sequence, of course. I don't see where the problem arises.
> If I had put to you the same question, which could have been you answer?
> 
> antonio


Hi again Gary,

your comment made me deepen a bit this expression, 
to make it "work very well".

If we want the same rule to apply to every sequence into the same line, 
this seems so not difficult: enough to delimit each with ( ), like this:
newString = originalString[1..2] &"INSERT" &(otherString[3..5] &[7..8]) &[5..9]

In such case, the "[5..9]" could clearly refer to the originalString, and so on.
_________

To this purpose we could even refine as the best syntax setting:
newString = originalString[1..2] &"INSERT" &otherString[3..5][7..8] &[5..9]

where the "&" operator becomes the variables level delimiter, 
so that we could have:
a = "abcdefrghjk"
A = "ABCDEFGHJK"
n = "123456789"

newString = a[1..2] & n[5..6] & "-INSERT-" & b[3..5][7..8] & [5..9] & [3..4]
--          a:ab      n:56                   b:CDE + GH     n:56789  a:cd

to get:
newString = "ab56-INSERT-CDEGH56789cd"

no?
 
antonio

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu