c# - 在 C# 中不使用正则表达式进行不区分大小写的替换?

标签 c# c#-4.0

有没有办法在不使用 C# 中的正则表达式的情况下对字符串进行不区分大小写的替换?

像这样

string x = "Hello";

x = x.Replace("hello", "hello world");

最佳答案

你可以尝试类似的东西

string str = "Hello";
string replace = "hello";
string replaceWith = "hello world";
int i = str.IndexOf(replace, StringComparison.OrdinalIgnoreCase);
int len = replace.Length;
str = str.Replace(str.Substring(i, len), replaceWith);

看看String.IndexOf Method (String, StringComparison)

关于c# - 在 C# 中不使用正则表达式进行不区分大小写的替换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3993826/

相关文章:

c# - 在非 UI 线程 Silverlight 5 浏览器应用程序中创建 UserControl

C# WatiN 下载文件 IE9

c# - 为什么 WebClient.OpenRead 在 Windows Server 2008 R2 上超时

regex - 仅当字符串中没有 "\r\n"时才替换 "."的正则表达式

c# - 序列不包含匹配元素错误使用 bool

visual-studio-2010 - 如何在 C#.net 中为目标用户创建桌面路径

c# - 如何替换已弃用的 csc ant 任务

c# - asp.net ObjectDataSource如何访问System.Web.UI.Page对象

c# - 在 Azure 中,Google Drive Api 文件上传失败,返回 null

c# - 是否存在这样的情况:我们需要一个具有被扩展对象的默认值的扩展方法?