简体   繁体   English

字符串信息类

[英]String Information Class

I am looking for something rather specific, and I don't really know what to call it. 我正在寻找比较具体的东西,我真的不知道该怎么称呼。 Let me explain: I require a small class/struct that takes a string and gathers information about it. 让我解释一下:我需要一个小的类/结构,它接收一个字符串并收集有关它的信息。 So I pass my string into the constructor and it "frisks" the string, gathering how many characters the string has, how many letters are in it, how many numbers, how many lower case letters, how many uppercase letters, how long it is, etc. I was about to develop this myself, but was wondering I it already existed within the .NET framework. 因此,我将我的字符串传递给构造函数,然后对字符串进行“整理”,收集字符串中有多少个字符,其中有多少个字母,多少个数字,多少个小写字母,多少个大写字母,多长时间等我自己开发,但是想知道它是否已经存在于.NET框架中。

Thanks. 谢谢。

No, this doesn't exist. 不,这不存在。 But it's simple enough to write yourself, you can do everything you require with a bit of LINQ and char extensions: 但是编写自己很简单,您可以使用一些LINQ和char扩展来完成所需的一切:

var count = str.Count();
var letters = str.Count(char.IsLetter);
var numbers = str.Count(char.IsDigit);
var lowers = str.Count(char.IsLower);
var uppers = str.Count(char.IsUpper);
//etc...

NO there is no such class exists in .NET Framework which gives you all the necessary details you are looking for. NO不存在这样的类中,给你所有你正在寻找必要的细节.NET框架存在。 You need to create it yourself. 您需要自己创建它。

Just my assumption after looking at the details you are looking into the string you might be looking for Verifying Password Strength 仅根据我的假设,在查看了详细信息之后,您正在寻找的字符串可能正在寻找验证密码强度

Have a look at the Char structure. 看一下Char结构。 It has lots of static functions like Char.IsDigit , Char.IsNumber , Char.IsLower 它具有很多静态函数,例如Char.IsDigitChar.IsNumberChar.IsLower

In addition to the System.String and System.Char classes to gather information, you can use classes in the System.Globalization namespace, such as StringInfo, TextInfo, CharUnicodeInfo and others. 除了System.String和System.Char类可以收集信息之外,还可以使用System.Globalization命名空间中的类,例如StringInfo,TextInfo,CharUnicodeInfo等。

Moreover, you can use the Character Classes in Regular Expressions. 此外,您可以在正则表达式中使用字符类 For example, Unicode Categories : diacritic marks, punctuation and others. 例如,Unicode 类别 :变音符号,标点符号等。 Or Unicode Named Blocks : IsGreek, IsCyrillic and many others. 或Unicode命名 :IsGreek,IsCyrillic等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM