Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

String manipulation: get tab contents until special sequence/truncate after special sequence?

in Questions Posts: 972

I need to read the contents of a tab but only part of it.

What I’d like to do is, on the tab to be read, put a special sequence behind a comment, maybe something like:


- - &$stophere#@

And only read the tab until there, or else read the whole tab and cut off everything after the special sequence.

Anyone know how I would do that?

Comments

  • dave1707dave1707 Mod
    Posts: 9,109

    @UberGoober No problem. I’ll whip something up.

  • dave1707dave1707 Mod
    Posts: 9,109

    @UberGoober Here it is. You can pick you own sequence and put it in the code. Right now I have —#* in the string find line. Enter the project and tab name then press find. It will print out the text up to the find sequence.

    viewer.mode=STANDARD
    
    function setup()
        parameter.text("project")
        parameter.text("tab")
        parameter.action("find",search)
    end
    
    function search()
        local temp=readProjectTab(project..":"..tab)
        local pos=string.find(temp,"--#*",1,true)
        if pos~=nil then
            local str=string.sub(temp,1,pos-1)
            print(str)
        else
            print("Not found")
        end
    end    
    
  • dave1707dave1707 Mod
    Posts: 9,109

    @UberGoober This can also be updated to create a new tab with the found text.

  • Posts: 972
    That’s fantastic, thanks!
Sign In or Register to comment.