tags:

views:

246

answers:

5

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

Things such as regular expressions and StringBuilders are useful for the gross manipulation of strings but they aren't what I'm looking for.

+2  A: 

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

Yuval
System.IO.Path, I guess?
hangy
+1  A: 

System.Text.StringBuilder and System.Text.RegularExpressions.Regex

torial
+4  A: 

Maybe System.Security.SecureString for strings which you do not want to be available 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();
}
hangy
+4  A: 
System.Net.Mail.MailAddress someMailAddress = new System.Net.Mail.MailAddress("[email protected]", "John Doe");
System.Console.WriteLine(someMailAddress.Address); // [email protected]
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" <[email protected]>

Does not change too much in the behaviour of the string, but provides a quite nice way of saving a mail address in a type-safe way. Also, this object can be added to a mail message object. :)

hangy
+2  A: 

I've seen several projects storing Guids either as their string representation or as byte[] instead of using the native Guid class.

Guid id = Guid.NewGuid()
Console.WriteLine(id);
Julio César