A set of extensions to the default String in .NET which I was missing
Between
- Returns a string between external strings or chars.BetweenAll
- Returns all strings between external strings or chars.Center
- Centers a string in a field of given width.CountOccurence
- Counts of a specified string in string.IsEmptyOrWhitespace
- Determines if string is empty or only consists of whitespaces.LeftOf
- Extracts a string left of a specified char \ string.RightOf
- Extracts a string right of a specified char \ string.ReplaceAmount
- Replaces a specified amount of string occurrence.Reverse
- Reverses a string.
You can find a variety of minimalistic examples in tests.
str = "#1$ #2$"
Console.WriteLine(
str.Between('#', '$')
);
Result: "1"
str = "#1$ #2$"
Console.WriteLine(
str.BetweenAll('#', '$')
);
Result: { "1", "2" }
str = "Text"
Console.WriteLine(
str.Center(14)
);
Result: " Text "
str = "12 12 12"
Console.WriteLine(
str.CountOccurence("12")
);
Result: 3
str = " "
Console.WriteLine(
str.IsEmptyOrWhitespace()
);
Result: true
str = "1234."
Console.WriteLine(
str.LeftOf('4')
);
Result: 123
str = ".1234"
Console.WriteLine(
str.RightOf('1')
);
Result: 234
str = "Some word for example"
Console.WriteLine(
str.ReplaceAmount("o", 2)
);
Result: "Sme wrd for example"
str = "123"
Console.WriteLine(
str.Reverse()
);
Result: "321"