Skip to content

Trimming Strings

abe545 edited this page Oct 29, 2014 · 1 revision

#Trimming Strings

Sometimes database data is messy. For instance, strings get entered with trailing (or leading) spaces. This can cause a lot of headaches when programming things like equality. Apparently "foo" != "foo "! Because of this, I have added the Trim attribute for model properties:

public class Model
{
    [Trim]
    public string Name { get; set; }
}

##Trimming All the Strings

If you have a lot of messy strings, and no leading/trailing whitespace is important to you, you can apply a global string trimmer:

var results = StoredProcedure.Create("usp_getDuplicateStrings")
                             .WithDataTransformer(new TrimAllStringsTransformer())
                             .WithResults<string>()
                             .Execute();

Clone this wiki locally