RE: Delete char in string
as in something like this... put char 2 to (the number of chars of fld 1) of fld 1 into fld 2 > Date: Wed, 19 Feb 2014 14:05:20 +0200 > From: richmondmathew...@gmail.com > To: use-livecode@lists.runrev.com > Subject: Delete char in string > > I am trying to do this: > > delete first char of $TEXT > > where $TEXT is a string > > and seem to be getting myself into trouble. > > Richmond > > ___ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your subscription > preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Delete char in string
On 19/02/14 14:09, John Dixon wrote: as in something like this... put char 2 to (the number of chars of fld 1) of fld 1 into fld 2 Exactly: nipping chars off strings in fields is dead easy: delete char 1 from field "MYCRAPPYTEXT" but I have a funny feeling that everything will move a whole lot quicker if one could do this sort of thing: delete char from $MYCRAPPYTEXT where the name with the $ is a string variable [Err . . guess my FORTRAN underwear is showing] Date: Wed, 19 Feb 2014 14:05:20 +0200 From: richmondmathew...@gmail.com To: use-livecode@lists.runrev.com Subject: Delete char in string I am trying to do this: delete first char of $TEXT where $TEXT is a string and seem to be getting myself into trouble. Richmond ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
RE: Delete char in string
It is really the same thing... put "Hello" into $MyCrappyText put char 2 to (the number of chars of $MyCrappyText) of $MyCrappyText into $MyCrappyText put $MyCrappyText > Date: Wed, 19 Feb 2014 14:22:08 +0200 > From: richmondmathew...@gmail.com > To: use-livecode@lists.runrev.com > Subject: Re: Delete char in string > > On 19/02/14 14:09, John Dixon wrote: > > as in something like this... > > put char 2 to (the number of chars of fld 1) of fld 1 into fld 2 > > > > > Exactly: > > nipping chars off strings in fields is dead easy: > > delete char 1 from field "MYCRAPPYTEXT" > > but I have a funny feeling that everything will move a whole lot quicker > if one could do this sort of thing: > > delete char from $MYCRAPPYTEXT > > where the name with the $ is a string variable [Err . . guess my > FORTRAN underwear is showing] > > >> Date: Wed, 19 Feb 2014 14:05:20 +0200 > >> From: richmondmathew...@gmail.com > >> To: use-livecode@lists.runrev.com > >> Subject: Delete char in string > >> > >> I am trying to do this: > >> > >> delete first char of $TEXT > >> > >> where $TEXT is a string > >> > >> and seem to be getting myself into trouble. > >> > >> Richmond > >> > >> ___ > >> use-livecode mailing list > >> use-livecode@lists.runrev.com > >> Please visit this url to subscribe, unsubscribe and manage your > >> subscription preferences: > >> http://lists.runrev.com/mailman/listinfo/use-livecode > > > > ___ > > use-livecode mailing list > > use-livecode@lists.runrev.com > > Please visit this url to subscribe, unsubscribe and manage your > > subscription preferences: > > http://lists.runrev.com/mailman/listinfo/use-livecode > > > ___ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your subscription > preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Delete char in string
On 19/02/14 14:09, John Dixon wrote: as in something like this... put char 2 to (the number of chars of fld 1) of fld 1 into fld 2 Oddly enough THIS works: put fld "INN" into $INN delete char 1 of $INN put $INN into fld "OWT" BUT, BUT, BIG UNCOMFORTABLE BUT, this: put fld "INN" into $INN put fld "URTEXT" into $URTEXT repeat until $URTEXT is empty if $INN contains the first char of $URTEXT then put the first char of $URTEXT after $OUTTEXT delete the first char of $URTEXT else delete the first char of $URTEXT end if end repeat put $OUTTEXT into fld "fOUTTEXT" Maybe this is because one cannot use CONTAINS with a string variable, Dunno. Richmond. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Delete char in string
What about: Replace char 1 of mystring with "" Bill William Prothero http://es.earthednet.org > On Feb 19, 2014, at 4:28 AM, Richmond wrote: > >> On 19/02/14 14:09, John Dixon wrote: >> as in something like this... >>put char 2 to (the number of chars of fld 1) of fld 1 into fld 2 > > Oddly enough THIS works: > > put fld "INN" into $INN > delete char 1 of $INN > put $INN into fld "OWT" > > BUT, BUT, BIG UNCOMFORTABLE BUT, this: > > > put fld "INN" into $INN > put fld "URTEXT" into $URTEXT > repeat until $URTEXT is empty > if $INN contains the first char of $URTEXT then > put the first char of $URTEXT after $OUTTEXT > delete the first char of $URTEXT > else > delete the first char of $URTEXT > end if > end repeat > put $OUTTEXT into fld "fOUTTEXT" > > Maybe this is because one cannot use CONTAINS with a string variable, Dunno. > > Richmond. > > ___ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your subscription > preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Delete char in string
On 19/02/14 14:28, Richmond wrote: On 19/02/14 14:09, John Dixon wrote: as in something like this... put char 2 to (the number of chars of fld 1) of fld 1 into fld 2 Oddly enough THIS works: put fld "INN" into $INN delete char 1 of $INN put $INN into fld "OWT" BUT, BUT, BIG UNCOMFORTABLE BUT, this: put fld "INN" into $INN put fld "URTEXT" into $URTEXT repeat until $URTEXT is empty if $INN contains the first char of $URTEXT then put the first char of $URTEXT after $OUTTEXT delete the first char of $URTEXT else delete the first char of $URTEXT end if end repeat put $OUTTEXT into fld "fOUTTEXT" Maybe this is because one cannot use CONTAINS with a string variable, Dunno. Or, is this because this line: repeat until $URTEXT is empty is rather silly? I don't just suppose one can have a string that is empty. If that be the problem [nice Subjunctive construction there, grammar groupies], how is one to finish one's REPEAT loop? I don't know if one could do this; repeat if $URTEXT exists sounds a bit odd. Richmond. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Delete char in string
On 19/02/14 17:42, Earthednet-wp wrote: What about: Replace char 1 of mystring with "" delete char 1 of $string works; that is not the problem. Richmond. Bill William Prothero http://es.earthednet.org On Feb 19, 2014, at 4:28 AM, Richmond wrote: On 19/02/14 14:09, John Dixon wrote: as in something like this... put char 2 to (the number of chars of fld 1) of fld 1 into fld 2 Oddly enough THIS works: put fld "INN" into $INN delete char 1 of $INN put $INN into fld "OWT" BUT, BUT, BIG UNCOMFORTABLE BUT, this: put fld "INN" into $INN put fld "URTEXT" into $URTEXT repeat until $URTEXT is empty if $INN contains the first char of $URTEXT then put the first char of $URTEXT after $OUTTEXT delete the first char of $URTEXT else delete the first char of $URTEXT end if end repeat put $OUTTEXT into fld "fOUTTEXT" Maybe this is because one cannot use CONTAINS with a string variable, Dunno. Richmond. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Delete char in string
Dunnit! The result may be downloaded here: http://forums.runrev.com/viewtopic.php?f=5&t=19188&p=96894#p96894 The "secret" if there is any secret at all, is that while I was working on the thing I did not "unload" each string variable between each go. Rather than repeat things endlessly here, I would urge interested parties to download the stack, mess around with it, and crack open the scripts of the 2 buttons. Richmond. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Delete char in string
On 2/19/14, 10:11 AM, Richmond wrote: The "secret" if there is any secret at all, is that while I was working on the thing I did not "unload" each string variable between each go. An easy trap to fall into. My big question is why you're using system variables. -- Jacqueline Landman Gay | jac...@hyperactivesw.com HyperActive Software | http://www.hyperactivesw.com ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Delete char in string
On 19/02/14 19:35, J. Landman Gay wrote: On 2/19/14, 10:11 AM, Richmond wrote: The "secret" if there is any secret at all, is that while I was working on the thing I did not "unload" each string variable between each go. An easy trap to fall into. My big question is why you're using system variables. Ha, Ha, ha: I'm just shoving a '$' in front of my variable names so that you and I can see that they are strings . . . . . . FORTRAN hangover I suppose. The '$' are strictly for those of us over "a certain age" . . . LOL Richmond. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Delete char in string
On Thu, Feb 20, 2014 at 12:11 AM, Richmond wrote: > > Rather than repeat things endlessly here, I would urge interested parties > to download the stack, mess around with it, > and crack open the scripts of the 2 buttons. > > In line with Geoff's recent post about riding the world of repeat loops which aren't 'repeat for each' because of the huge benefit of scaling repeat for each has over other forms, I thought I'd benchmark your code. My results for 1,000,000 Unicode chars Your Repeat Until = 237621 ms Repeat for each = 0 ms I couldn't believe it either so you'll see I inserted a breakpoint in my code just to cofirm it was actually recording the time correctly - but unless you use the Debugger and step through code checking variable values this may be obvious. So I commented out your repeat and then tested repeat for each only and it wasn't until 819,200,000 Unicode characters did I get a 1 ms test time. After that I started crashing LC as I assume I was hitting some limit. , In a New Stack, in a new button - the output is directed to the Message Box: on mouseUp --breakpoint --create a random list of 20 ASCII chars between ASCII32 - ASCII 125 repeat 20 times put numToChar(random(94) + 31) after tLIST end repeat ask "How many characters do you want to process" with 10 titled "Enter Digits Only - No Punctuation" put it into tNumOfChars answer "Do you wish to test against Unicode chars?" with "Yes" or "No" titled "Test Unicode" put it into tUniCode if (tUniCode = "Yes") then set the useUnicode to true put 65535 into tUpperLimit else put 255 into tUpperLimit end if repeat tNumOfChars times put numToChar(random(tUpperLimit)) after tORIGIN end repeat --so the 2nd test is identical put tORIGIN into tORGIN2 --TEST 1 TIMING put the millisec into tStartTime repeat until tORIGIN is empty if tLIST contains the first char of tORIGIN then put the first char of tORIGIN after tOUTPUT delete the first char of tORIGIN else delete the first char of tORIGIN end if --put $ORIGIN into fld "fORIGIN2"--not required end repeat put tOUTPUT into tTest1 put the millisec into tEndTime put tEndTime - tStartTime into tTest1Time --TEST 2 TIMING put the millisec into tStartTime repeat for each char tChar in tORIGIN2 if (tLIST contains tChar) then put tCHAR after tOUTPUT2 end if end repeat put tOUTPUT into tTest2 --breakpoint put the millisec into tEndTime put tEndTime - tStartTime into tTest2Time if (tTest1 = tTest2) then put "Repeat Until: " & tTest1Time & cr & \ "Repeat for Each: " & tTest2Time into msg else put "Failed - Outputs not equal" into msg end if beep --breakpoint end mouseUp ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Delete char in string
Aren’t those constants? Can you edit constants like variables? Bob On Feb 19, 2014, at 04:05 , Richmond wrote: > I am trying to do this: > > delete first char of $TEXT > > where $TEXT is a string > > and seem to be getting myself into trouble. > > Richmond > > ___ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your subscription > preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Delete char in string
I hate it when I post too quickly. 0 ms was just too good to be true so I investigated further and found 2 errors in my code. The real figures are 10,000 Unicode Repeat Until: 19 ms Repeat for Each: 3 ms 100,000 Unicode Repeat Until: 1823 ms Repeat for Each: 30 ms 1,000,000 Unicode Repeat Until: 236688 ms Repeat for Each: 295 ms Which still proves the point that 'repeat for each' scales much better than other repeat forms. Corrected script below: on mouseUp --breakpoint --create a random list of 20 ASCII chars between ASCII32 - ASCII 125 set the useUnicode to false put empty into tLIST repeat 20 times put numToChar(random(94) + 31) after tLIST end repeat ask "How many characters do you want to process" with 10 titled "Enter Digits Only - No Punctuation" put it into tNumOfChars answer "Do you wish to test against Unicode chars?" with "Yes" or "No" titled "Test Unicode" put it into tUniCode if (tUniCode = "Yes") then set the useUnicode to true put 65535 into tUpperLimit else put 255 into tUpperLimit end if repeat tNumOfChars times put numToChar(random(tUpperLimit)) after tORIGIN end repeat put the number of chars in tORIGIN into msg --so the 2nd test is identical put tORIGIN into tORIGIN2 --TEST 1 TIMING put the millisec into tStartTime repeat until tORIGIN is empty if tLIST contains the first char of tORIGIN then put the first char of tORIGIN after tOUTPUT delete the first char of tORIGIN else delete the first char of tORIGIN end if --put $ORIGIN into fld "fORIGIN2"--not required end repeat put tOUTPUT into tTest1 put the millisec into tEndTime put tEndTime - tStartTime into tTest1Time --TEST 2 TIMING put the millisec into tStartTime repeat for each char tChar in tORIGIN2 if (tLIST contains tChar) then put tChar after tOUTPUT2 end if end repeat put tOUTPUT2 into tTest2 --breakpoint put the millisec into tEndTime put tEndTime - tStartTime into tTest2Time --breakpoint if (tTest1 = tTest2) then put "Repeat Until: " & tTest1Time & " ms" & cr & \ "Repeat for Each: " & tTest2Time & " ms" into msg else put "Failed - Outputs not equal" into msg end if beep --breakpoint end mouseUp ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Delete char in string
On Thu, Feb 20, 2014 at 10:03 AM, Bob Sneidar wrote: > Aren't those constants? Can you edit constants like variables? > No, they are variables. From the Dictionary: Use this technique to create your own environment variables. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode