Path: csiph.com!aioe.org!.POSTED!not-for-mail From: Lino Newsgroups: comp.programming Subject: Re: A problem about programming Date: Thu, 24 Nov 2016 11:18:20 +0100 Organization: Aioe.org NNTP Server Lines: 101 Message-ID: References: NNTP-Posting-Host: hPlHszvYrE9msYmsjUlyaw.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.2 Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAMFBMVEUCAgI2MiZAsvKk1/Dxz pLx1Jrx3KTy57Tz9cfb7fPo8vPx9vP2+PP4+PP///8AAABAWc5lAAAAB3RJTUUH0wsIEyMtDwzr4gA AAd5JREFUeJx11Dtu20AQBuBf8VJaAyaREwgCTyCAF1gDq56F1zUrqmVHlyzZBq58BHVJm8p10qi3F 2AuwDNkZh8yKdoLCBLm4w5n9iGMPABk43yAPgP6vu+yBQxrI5dCsDIPiqDHNSQPWksnPu8qwGAUVg7 6joqQISeBpkRdPxkB/glKNINteMcCEKtSDqgZ/6a+i32IxycwdJIrIxhoIXyF4BAF0Uueizzfha4oG TqJjhNSOM8RgPJ0PIXTfaP4bozrIPlhSGI3YZcFGJqGypG4vSl4Qp5H2DRo21bidFMU+TSVh83d6dl DdoGWR5P+/uFgN16B/fniILvA+siQnv/cFnu4HiLUdX1sU/v6UmB/OQxUbbWuiNLz31NRLKGy6RuVl U0gKZOyrnG2BPtrwDpL7fvpOa6ey2SQlELB2vdf8Uj6bdSCZiQEFmYKQgsBcZ9aezbldgqK4lCWWjP lx0nkk6WVUJkQ9ISaAZho6ynnHHjQBGjMAAHcl5pU5SLK8xLi+BL0NVAPnwFwMBU+AaESU1fCFYF4D UZu7wBDGwLxnc/39mNJDpuO4NhAxrsWAEjMIx2H9ileqbjs+gvQiqGCh5iKF0sdSsBd8/Dn4beeIio cJLJLuS4Q+uKQ+/kf+4Ng9WQ79vEAAAAASUVORK5CYII= X-Newsreader: MesNews/1.08.06.00-it Xref: csiph.com comp.programming:7005 Scriveva Richard Heathfield giovedì, 24/11/2016: > On 23/11/16 21:38, Lino wrote: > >> >> 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.