Extract name from string

<span>Hi,<br /> I' m trying to extract a name from a string that starts and ends with a <pre><code class="language-igor"><</code></pre> and <pre><code class="language-igor">></code></pre> which I'm trying to get rid of. I've been using <pre><code class="language-igor">sscanf </code></pre>and it works for the lesser than sign at the beginning but not the other sign at the end. <br /> <br /> <pre><code class="language-igor"> function test() string name sscanf "<Signal001>", "%*[<]%s%*[>]", name print name end </code></pre><br /> As a result I get: <pre><code class="language-igor">Signal001></code></pre><br /> <br /> Any suggestions ?</span>
Try this:

function test()
 
    String s0="<Signal001>"
    string name
    String regExp="(?<=<)(.+)(?=>)"
    SplitString/E=regExp s0,name
    print name
 
end
Because you want to remove the first and last characters from the string, this will work as well:

function test()
 
    string name =  "<Signal001>"
    name = name[1, strlen(name) - 2]
    print name
 
end


In  name[1, strlen(name) - 2], the "1" and "-2" are required to remove the first and last characters because string indexing is zero based in Igor.
Neodyme wrote:
I've been using sscanf and it works for the lesser than sign at the beginning but not the other sign at the end.


Others already posted versions which work, so I'll just focus on why this does not work.
The reason is that the "%s" specifier also eats the ">". In your case you could get away with

function test()
 
    string name
    sscanf "<Signal001>", "<%[A-Za-z0-9]>", name
    print name
end


but I personally lean towards the regexp as that is the most generic solution.
Sounds like you have a good solution using regular expressions, but the ReplaceString function is also very easy to use, assuming the "<" and ">" characters would never show up in the name.
string name=ReplaceString("<",ReplaceString(">","<Signal1001>",""),"")