Return default value if current string is empty, equals null or equals white space, otherwise current string.
var result =" ".DefaultIfEmpty("defaultValue"); // defaultValuevar result ="someValue".DefaultIfEmpty("defaultValue"); // someValue
Cast
Casts string to specified type or throws if cast is impossible and throwIfInvalidCast set to true.
var result ="123,45".Cast(typeof(float?),true); // 123.45Fvar result ="123,45abc".Cast(typeof(float?),true); // throws InvalidCastExceptionvar result ="123,45abc".Cast(typeof(float?),false); // nullprivateenumFooBarBaz{ Foo, Bar, Baz}var result ="Bar".Cast(typeof(FooBarBaz?),false); // FooBarBaz.Bar
ToHyphenCase
Formats string value into hyphen case format. For example "ToHyphenCase" will be formated into "to-hyphen-case".
ToCamelCase
Formats string value into camel case format. For example "ToCamelCase" will be formated into "toCamelCase".
ToSnakeCase
Formats string value into snake case format. For example "ToSnakeCase" will be formated into "to_snake_case".
Contains
Returns a value indicating whether a specified string occurs within this string, using the specified comparison rules. Method could be useful to projects prior to .net standard 2.1. Similar method added to string in .net standard 2.1.
Replace
Returns a new string in which all occurrences of a specified string in the current instance are replaced with another specified string using provided comparison rule. Method could be useful to projects prior to .net standard 2.1. Similar method added to string in .net standard 2.1.
var result = "ToHyphenCase".ToHyphenCase() // to-hyphen-case
var result = "ToCamelCase".ToCamelCase() // toCamelCase
var result = "ToSnakeCase".ToSnakeCase() // to_snake_case
var result = "QwErTy".Contains("wert", StringComparison.Ordinal) // false
var result = "QwErTy".Contains("wert", StringComparison.OrdinalIgnoreCase) // true
var result = "QwErTyQwErTy".Replace("WeR", "123", StringComparison.Ordinal) // QwErTyQwErTy
var result = "QwErTyQwErTy".Replace("WeR", "123", StringComparison.OrdinalIgnoreCase) // Q123TyQ123Ty