What are some string encapsulation classes that define both the meaning and behavior for their contents?

.NET has System.Uri for Uris and System.IO.FileInfo for file paths. I am looking for classes that are traditionally object-oriented because they define both the meaning and behavior for the string that is used in constructing the object. What other useful encapsulation string classes exist?

Things like regular expressions and StringBuilders are useful for rude string manipulation, but they are not what I'm looking for.

+4
source share
5 answers

Perhaps System.Security.SecureString is for strings you don't want to use in public memory.

using (System.Security.SecureString password = new System.Security.SecureString()) { password.AppendChar('s'); password.AppendChar('e'); password.AppendChar('c'); password.AppendChar('r'); password.AppendChar('e'); password.AppendChar('t'); password.MakeReadOnly(); } 
+4
source
 System.Net.Mail.MailAddress someMailAddress = new System.Net.Mail.MailAddress(" me@example.org ", "John Doe"); System.Console.WriteLine(someMailAddress.Address); // me@example.org System.Console.WriteLine(someMailAddress.User); // me System.Console.WriteLine(someMailAddress.Host); // example.org System.Console.WriteLine(someMailAddress.DisplayName); // John Doe System.Console.WriteLine(someMailAddress); // "John Doe" < me@example.org > 

It doesn't change too much in the behavior of the string, but it provides a pretty good way to save the email address in a safe way. In addition, this object can be added to the mail message object. :)

+4
source

Probably trivial, but there is also System.IO.DirectoryInfo and System.Info.Path

+2
source

I saw several projects storing Guides, either as their string representation, or as byte [] instead of using Guid's own class.

 Guid id = Guid.NewGuid() Console.WriteLine(id); 
+2
source

System.Text.StringBuilder as well as System.Text.RegularExpressions.Regex

+1
source

Source: https://habr.com/ru/post/1277455/


All Articles