C# Remove 兩種刪除字符方法

namespace ConsoleApplication1
{
class Program{
static void Main(string[] args)
{
//聲明一個Str1字符串並賦值。
string str1 = "刪除字符";
//聲明一個Str2字符串,並使用Remove方法從字符串str1的索引從2開始刪除。
string str2 = str1.Remove(2);
//聲明一個Str3字符串,並使用Remove方法從字符串str1的索引從0開始刪除2個字符。
string str3 = str1.Remove(0, 2);
Console.WriteLine(str2);
Console.WriteLine(str3);
Console.ReadLine();
}
}
}

發佈了70 篇原創文章 · 獲贊 6 · 訪問量 20萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章