Home > Community > Forums > Custom IC SKILL > String operations in skill

Email

* Required Fields

Recipients email * (separate multiple addresses with commas)

Your name *

Your email *

Message *

Contact Us

* Required Fields
First Name *

Last Name *

Email *

Company / Institution *

Comments: *

 String operations in skill  

Last post Thu, Aug 15 2013 9:07 AM by theopaone. 2 replies.
Started by shazzy 13 Aug 2013 11:09 PM. Topic has 2 replies and 574 views
Page 1 of 1 (3 items)
Sort Posts:
  • Tue, Aug 13 2013 11:09 PM

    • shazzy
    • Not Ranked
    • Joined on Tue, Apr 2 2013
    • Bangalore, Karnataka
    • Posts 7
    • Points 155
    String operations in skill Reply

    Okay so we have a list 'p' constituting of elements as pin names. 

     p = ("GIO<0>"  "G1E<1>"  "GAE2<2>"  "G3F1<3>")

     

    And the task is to add the under-braces numeric value with 4 and convert this array into

      p = ("GIO<4>"  "G1E<5>"  "GAE2<6>"  "G3F1<7>")

     

    I did these operations in perl and also bridged the gap between perl and skill. 

    But since this script has to be linked to a bind key hence I want to do the string operations in skill only. 

    Is there any skill code or so by which we can edit the numeric portion ( only under the braces) of the string and then return it back to the 'p' array?

    • Post Points: 20
  • Thu, Aug 15 2013 7:14 AM

    • dmay
    • Top 25 Contributor
    • Joined on Thu, Jul 17 2008
    • Allen, TX
    • Posts 393
    • Points 7,415
    Re: String operations in skill Reply

    Here is one way to do it:

    p = list("GIO<0>"  "G1E<1>"  "GAE2<2>"  "G3F1<3>")

    procedure(myAdjustBit(nameList delta)
      let((newNameList parsed prefix suffix newSuffix newName)
        foreach(name nameList
            parsed=parseString(name "<>")
            prefix=car(parsed)
            suffix=evalstring(cadr(parsed))
            newSuffix=suffix+delta
            newName=sprintf(nil "%s<%d>" prefix newSuffix)
            newNameList = cons(newName newNameList)
        )
        reverse(newNameList)
      ) ;let
    ) ;proc

    myAdjustBit(p 4)

    Derek

    • Post Points: 20
  • Thu, Aug 15 2013 9:07 AM

    • theopaone
    • Top 75 Contributor
    • Joined on Tue, Feb 12 2013
    • Cedar Park, TX
    • Posts 106
    • Points 1,600
    Re: String operations in skill Reply

     Thanks, Derek. I had forgotten that parseString can take more than one parsing character

     Ted

    • Post Points: 5
Page 1 of 1 (3 items)
Sort Posts:
Started by shazzy at 13 Aug 2013 11:09 PM. Topic has 2 replies.