Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.programming > #7005

Re: A problem about programming

From Lino <lino@net.com>
Newsgroups comp.programming
Subject Re: A problem about programming
Date 2016-11-24 11:18 +0100
Organization Aioe.org NNTP Server
Message-ID <mn.c2a67e0b772051a3.142705@net.com> (permalink)
References <mn.bc7d7e0bef53dd75.142705@Kiss-the-Sphinx> <o1500m$m4q$1@dont-email.me> <mn.bd4e7e0be141a73c.142705@Kiss-the-Sphinx> <o16c26$eqd$1@dont-email.me>

Show all headers | View raw


Scriveva Richard Heathfield giovedì, 24/11/2016:
> On 23/11/16 21:38, Lino wrote:
> <snip>
>>
>> this (below) work partially and it have 2 problem:
>>
>>        st.Ticker= "IT_"+StrRight(ticker,Lenght+3);

> I think you mean "Length", not "Lenght".

> I note that you wish the replacement substring to be "IT_" (and I think 
> this is the first time you have mentioned this).

>> 1. change only 1 symbol a time (I think it's a "FOR Cycle" problem)
>>
>> 2.
>>
>> Example: I have symbols [below] -----> and  result
>>
>> TO:A       TC-T:A  wrong
>> TO:DE      TC-:DE  wrong
>> TO:ASD     TC-ASD  OK OK OK OK
>> TO:AXMA    TC-XMA  Wrong
>> TO:ERJTT   TC-JTT  wrong
>>
>> I want to change "only" the "TO:" or the part of string that I want to
>> change leaving the rest the same as originally printed.
>>
>> Hope I'an clear
>> Thanks for help.

> So, if your other follow-up is correct, this isn't VBScript /or/ 
> JavaScript, but something called AFL. Okay.

> Specification: replace the first three characters of a string with three 
> different supplied characters.

> This AFL solution assumes that "TO:" will only occur once in the string:

> StrReplace(st.Ticker, "TO:", "IT_");

> And that's it! A one-line solution.

> But if you are concerned that "TO:" might also occur elsewhere in the 
> string, then StrReplace won't do it, because it replaces all occurrences, 
> not just the first, in which case you'll need to do something like:

> st.Ticker = "IT_" + strmid(st.Ticker, 3);

> This assumes you are using AFL 5.90 or later, which allows you to omit the 
> final length argument. Otherwise, you will have to do this:

> Length = strlen(st.Ticker);
> st.Ticker = "IT_" + strmid(st.Ticker, 3, Length - 3);

> More generally, if you wish to replace the FIRST occurrence of a particular 
> symbol OLD with some new symbol NEW, no matter where in the string OLD 
> occurs, then you can do something like this (where // introduces a comment 
> --- I don't know what the actual AFL comment syntax is):

> old = "TO:"; // replace "TO:" with whatever you want out
> new = "IT_"; // replace "IT_" with whatever you want in
> left = "";
> centre = new;
> right = "";
> st = sts.Item(i); // I'll have to trust you that this is correct
> startpos = StrFind(st.Ticker, old); // where is the old string?
> if(startpos > 0) // we have a match
> {
>    if(startpos > 1) // we need to save the part before the match
>    {
>      left = StrLeft(st.Ticker, startpos); // first part saved
>    }

>    // now we need to save the part /after/ the match.
>    // The part after the match will be the length of the string,
>    // LESS the length of the bit you want to get rid of, LESS
>    // the length of the part we already accounted for.

>    rightlength = StrLen(st.Ticker) - StrLen(old) - StrLen(left);

>    // Now we can save the part after the match

>    right = StrRight(st.Ticker, rightlength);

>    // The easy bit: adding together all the bits we want to keep.

>    st.Ticker = left + centre + right;
> }

> How does that work for you? (I can't test it because I don't have access to 
> AFL.)


I have AFL version 5.70.

Thank you very much for your patience.


  I test all (and correct my errors) above today in the afternoon and I'll 
send you a reply as soon as possible.

Back to comp.programming | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

A problem about programming Lino <lino@net.com> - 2016-11-23 19:09 +0100
  Re: A problem about programming Richard Heathfield <rjh@cpax.org.uk> - 2016-11-23 19:36 +0000
    Re: A problem about programming Lino <lino@net.com> - 2016-11-23 21:04 +0100
    Re: A problem about programming Lino <lino@net.com> - 2016-11-23 23:38 +0100
  Re: A problem about programming Richard Heathfield <rjh@cpax.org.uk> - 2016-11-23 21:01 +0000
    Re: A problem about programming Richard Heathfield <rjh@cpax.org.uk> - 2016-11-23 21:02 +0000
    Re: A problem about programming Lino <lino@net.com> - 2016-11-23 22:38 +0100
      Re: A problem about programming Lino <lino@net.com> - 2016-11-23 22:40 +0100
      Re: A problem about programming Richard Heathfield <rjh@cpax.org.uk> - 2016-11-24 09:33 +0000
        Re: A problem about programming Lino <lino@net.com> - 2016-11-24 11:18 +0100
          Re: A problem about programming Lino <lino@net.com> - 2016-11-24 12:49 +0100
            Re: A problem about programming Richard Heathfield <rjh@cpax.org.uk> - 2016-11-24 12:08 +0000
        Re: A problem about programming Lino <lino@net.com> - 2016-11-24 14:08 +0100
        Re: A problem about programming BartC <bc@freeuk.com> - 2016-11-24 17:14 +0000
          Re: A problem about programming Richard Heathfield <rjh@cpax.org.uk> - 2016-11-24 17:18 +0000

csiph-web