Question

Given the following string:

string Header =">day11:1:356617";

How do you extract everything except ">", yielding only:

day11:1:356617

I could do standard loop over the string character and keep only other than ">".

string nStr ="";
for (int i=0; i < Header.size(); i++) {
    if (Header[i] != ">") {
       nStr = nStr + Header[i];
     }
}

But the approach seems too clumsy and slow, in particular I need to do such extraction for millions of lines.

Was it helpful?

Solution

if (Header[0] == '>') Header = Header.substr(1);

OTHER TIPS

...You didn't say anything about the "domain" of the inbound strings or what you're looking to chomp. If it's just strings of the form you gave, this would be the fastest:

Header.substring(1);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top