C#中怎样从指定字符串中查找并替换字符串

2025-03-12 23:13:23
推荐回答(1个)
回答1:

使用字符串的IndexOf方法查找,找到返回正确的位置下标,未找到返回-1举例:string str = "我爱北京天安门"; int index = str.IndexOf("爱"); if (index > -1) { Console.Write("找到了"); } else { Console.Write("未找到"); } Console.Read();