views:

161

answers:

2

Hi,

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.

+3  A: 
if (Header[0] == '>') Header = Header.substr(1);
Simon Buchan
+1  A: 

...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);
Richard T
This is C++, std::string has no substring() method.
Simon Buchan
Not that your *answer* is wrong.
Simon Buchan