Rick Harrison wrote:

>> On Jun 22, 2017, at 2:17 PM, Mark Talluto wrote:
>>
>> On Jun 22, 2017, at 11:03 AM, Rick Harrison wrote:
>>>
>>> I have a string variable which contains over 2500 characters.
>>> I only want to grab the first 1000 characters of that string.
>>> Rather than looping 1000 times to grab each character
>>> is there a way to just grab the first 1000 efficiently in
>>> one big chunk?
>>
>> Hi Rick,
>>
>> put char 1 to 1000 of tOriginalVar into tNewVar
>
> Thanks for this solution.
>
> Does that statement create an implied loop?
> It’s great for a one liner though!


With many chunk expressions, I would imagine it does. With line chunks, for example, the engine needs to walk through the string, comparing each character to CR, counting the found CRs as it goes.

But even then, better to have the engine do that in machine code than for us to do it in script. :)

In this case, though, I believe it doesn't need a loop per se, since AFAIK character are fixed-size entities internally (Mark Waddingham, is that true that UTF-16 gives us two-bytes per char across the board?).

If I'm mistaken there, any traversal of the string is still about as efficient as it's going to get in a general-purpose language, since it's relying on the well-optimized Unicode libraries many projects depend on.

All that said, as much as I enjoy benchmarking I wouldn't sweat use-cases involving small data. 1k chars could be sliced with any chunk type so quickly it probably won't matter.

--
 Richard Gaskin
 Fourth World Systems
 Software Design and Development for the Desktop, Mobile, and the Web
 ____________________________________________________________________
 ambassa...@fourthworld.com                http://www.FourthWorld.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

Reply via email to