Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to split locals' names into two parts

    Hi folks,

    i couldn't find a solution for my problem. I have the following variable list with not only two but possibly up to 200 "variable" names:

    Code:
    local sheetlist "57-C_PPP 57A-C_NC"
    I would like to split each string within my sheetlist by the delimiter "-". The part following the delimiter is my actual variable name. I tried to use the split command but i don't think this works for local variable names.


    I also have got another problem. I would like to import a string from just one single excel cell and want to store it in order to use it for the label of a variable in my data set. Which type of import makes more sense to achieve my goal? The cell A3 contains the text I would like to store.

    Code:
    import excel MSTI_2015-2.xlsx, sheet("57-C_PPP") cellrange(A3:A3)
    import excel MSTI_2015-2.xlsx, sheet("57-C_PPP") cellrange(A3:A3) firstrow


    Does anyone have any suggestions which commands to use?




    Thanks a lot!

  • #2
    Here is one way

    Code:
    local sheetlist "57-C_PPP 57A-C_NC"
    foreach name of local sheetlist {
        local pos = strpos("`name'", "-") + 1
        local name = substr("`name'", `pos', .)
        local newlist `newlist' `name'
    }
    display "`newlist'"
    For more type

    Code:
    help string functions
    Best
    Daniel

    Comment


    • #3
      It's really the contents of the local macro, not the names of the local macros, that you want to split. I mention this for anyone confused by the thread title.

      The command split is indeed for data, and doesn't apply otherwise.

      Comment


      • #4
        Daniel, thanks for the code. i knew these commands you used (strpos and substr) but i didn't know they would work for macros as well. i am a bit angry with myself. i think i should have been able to do this.

        sorry for the misunderstanding in the title. i am still too confused with all these different expressions. i try to be more precise next time.

        concerning the second problem i could deal with it. so that's it luckily.

        thanks a lot!

        Comment

        Working...
        X