提取部分字符串的紧凑方式(FASTA 标头)

发布于 2024-07-14 21:52:53 字数 405 浏览 7 评论 0原文

给定以下字符串:

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

如何提取除“>”之外的所有内容, 仅产生:

day11:1:356617

我可以对字符串字符进行标准循环 并仅保留“>”以外的内容。

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

但该方法似乎 太笨拙和缓慢,特别是我需要这样做 提取数百万行。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瑾兮 2024-07-21 21:52:53
if (Header[0] == '>') Header = Header.substr(1);
if (Header[0] == '>') Header = Header.substr(1);
红衣飘飘貌似仙 2024-07-21 21:52:53

...您没有说任何关于入站字符串的“域”或您想要剪切的内容。 如果它只是您给出的形式的字符串,这将是最快的:

Header.substring(1);

...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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文