D的双循环去分号.

string stripsemicolons(string s)
{
  string result;
  // prevent reallocations
  result.length = s.length;
  result.length = 0;

  //append to string only when needed
  size_t i = 0;
  while (i < s.length)
  {
    size_t j = i;
    while (i < s.length && s[i] != ';')
      ++i;
    result ~= s[j..i];
  }
}
posted @ 2021-12-10 20:56  zjh6  阅读(13)  评论(0)    收藏  举报  来源