gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 23:11:07 25 4
gpt4 key购买 nike

有没有办法在不使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com