當前位置:編程學習大全網 - 電腦編程 - 給位老師:在c#中如何判斷壹個字符串內含有的空格數請給出具體代碼?

給位老師:在c#中如何判斷壹個字符串內含有的空格數請給出具體代碼?

static?int?Count(string?WithinString,?string?search)

{

if?(string.IsNullOrEmpty(search))

throw?new?ArgumentNullException("search");

int?counter?=?0;

int?index?=?WithinString.IndexOf(search,?0);

while?(index?>=?0?&&?index?<?WithinString.Length)

{

counter++;

index?=?WithinString.IndexOf(search,?index?+?search.Length);

}

return?counter;

}

然後用Count(要查找的字條串," ") 就可以取空格數量了

  • 上一篇:醋中的黑色顆粒沈澱是什麽?
  • 下一篇:LED08C快速門顯示er 10
  • copyright 2024編程學習大全網