Strings Don’t Add Up

4 Comments »

One way to format C# strings is to add strings together using the plus-sign operator, such as:

string fileStats =
    "Bytes=" + bytes.ToString() +
    ", Pages=" + pages.ToString() +
    ", Words=" + words.ToString();

This code will correctly produce the desired output but is inefficient and does not scale as well.

Read the rest of this entry »

String.IsNullOrEmpty Shootout

5 Comments »

Given a string ‘s’, which of the following expressions is faster?

1. String.IsNullOrEmpty( s )

2. s == null || s.Length == 0

Read the rest of this entry »

C# String Tips

90 Comments »

The .NET string class is quite comprehensive, yet some common string functions are missing or not entirely obvious. This article provides quick tips on using .NET strings.

Read the rest of this entry »