ToStringLimit(limit)

public static string ToStringLimit(this String str, int limit) {
  if (str.Length > limit) {
    return str.Substring(0, limit);
  }

  return str;
}
Example:
string test = "hello world";

// set hi to test value
// but maybe hi is being saved into the database and
// it only stores max length of 5.

string hi = test.ToStringLimit(5);

// hi = "hello"
// saves you having to first check length then using substr
// nice little extension helper :)

Description

Save values checking length

Details

Double click on the code to select all.

 

;