Author Topic: Efficient Sub-String Method  (Read 2106 times)

0 Members and 1 Guest are viewing this topic.

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Efficient Sub-String Method
« on: February 10, 2010, 10:00:41 pm »
Here's my favorite way of using sub(.
The idea of this is to use sub( and sum( in an odd manner.
ex:
:3->A //You want the third item
:{1,6,6,5,1,4,1 // 1 followed by the lengths of the Item. (Item 1 has a length of 6, Item 2 has a length of 6, Eeems has a length of 5... )
:sub("Item 1Item 2Eeems455556",sum(Ans,1,A),Ans(A+1 //sub(String,Add to get to spot,Length of Item

This results with the third item, "Eeems". ;D
I hope this helped someone.  What do you guys think?

Offline Eeems

  • Mr. Dictator
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6266
  • Rating: +318/-36
  • little oof
    • View Profile
    • Eeems
Re: Efficient Sub-String Method
« Reply #1 on: February 11, 2010, 12:04:34 am »
Hmm, looks interesting, I'll have to test it...it might help with when I do string indexing.
/e

Offline Galandros

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1140
  • Rating: +42/-10
    • View Profile
Re: Efficient Sub-String Method
« Reply #2 on: February 11, 2010, 07:45:57 am »
Nice code.

I also like tricks with instring( and sub( together. They are pretty efficient.
Hobbing in calculator projects.