不区分大小写替换,而不在C#中使用正则表达式? [英] Case insensitive replace without using regular expression in C#?

查看:375
本文介绍了不区分大小写替换,而不在C#中使用正则表达式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法做不区分大小写替换字符串没有在C#中使用正则表达式?



像这样

 字符串x =你好; 

X = x.Replace(你好,世界你好);


解决方案

您可以尝试像

 字符串str =你好; 
替换字符串=你好;
串replaceWith =Hello World的;
INT I = str.IndexOf(更换StringComparison.OrdinalIgnoreCase);
INT LEN = replace.Length;
海峡= str.Replace(str.Substring(I,LEN),replaceWith);

有一个看的 String.IndexOf方法(String,StringComparison)


Is there a way to do case insensitive replace on a string without using regular expression in C#?

something like this

string x = "Hello";

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

解决方案

You can try something like

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);

Have a look at String.IndexOf Method (String, StringComparison)

这篇关于不区分大小写替换,而不在C#中使用正则表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆