是.NET字符串操作区分大小写? [英] Are .NET string operations case sensitive?

查看:241
本文介绍了是.NET字符串操作区分大小写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是.NET字符串函数如的IndexOf(嗒嗒)区分大小写?

Are .NET string functions like IndexOf("blah") case sensitive?

这是我记得他们都没有,但出于某种原因,我在我的应用程序,其中的查询字符串中的文本是骆驼的情况下(如用户名)看到错误和(用户id),我测试了的IndexOf

From what I remember they aren't, but for some reason I am seeing bugs in my app where the text in the query string is in camel case (like UserID) and I'm testing for IndexOf("userid").

推荐答案

是的,字符串函数的情况下默认为敏感。它们通常具有过载,让你注明你要的那种字符串比较。这也是真实的对indexOf。为了让您的字符串的索引,在不区分大小写的方式,你可以这样做:

Yes, string functions are case sensitive by default. They typically have an overload that lets you indicate the kind of string comparison you want. This is also true for IndexOf. To get the index of your string, in a case-insensitive way, you can do:

string blaBlah = "blaBlah";
int idx = blaBlah.IndexOf("blah", StringComparison.OrdinalIgnoreCase);

这篇关于是.NET字符串操作区分大小写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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