Enhanced C#
Language of your choice: library documentation
|
Extension methods for strings, such as SplitAt, Left, Right, Format and USlice. More...
Static Public Member Functions | |
static Pair< UString, UString > | SplitAt (this string s, char delimiter) |
Gets the substrings to the left and right of a dividing character. More... | |
static Pair< UString, UString > | SplitAt (this string s, string delimiter) |
static string | Right (this string s, int count) |
Returns the rightmost 'count' characters of 's', or s itself if count > s.Length. More... | |
static string | Left (this string s, int count) |
Returns the leftmost 'count' characters of 's', or s itself if count > s.Length. More... | |
static char | TryGet (this string s, int index) |
static char | TryGet (this string s, int index, char defaultValue) |
static char | TryGet (this StringBuilder s, int index) |
static char | TryGet (this StringBuilder s, int index, char defaultValue) |
static string | SafeSubstring (this string s, int startIndex, int length=int.MaxValue) |
A variation on String.Substring() that never throws. More... | |
static string | Join (string separator, IEnumerable value) |
Converts a series of values to strings, and concatenates them with a given separator between them. More... | |
static string | Join (string separator, IEnumerator value) |
static UString | USlice (this string str, int start, int count=int.MaxValue) |
static UString | Find (this string str, UString what, bool ignoreCase=false) |
static string | FormatCore (this string format, params object[] args) |
This formatter works like string.Format, except that named placeholders accepted as well as numeric placeholders. This method replaces named placeholders with numbers, then calls string.Format. More... | |
static string | EliminateNamedArgs (string format, params object[] args) |
Called by Format to replace named placeholders with numeric placeholders in format strings. More... | |
|
inlinestatic |
Called by Format to replace named placeholders with numeric placeholders in format strings.
Referenced by Loyc.StringExt.FormatCore().
|
inlinestatic |
This formatter works like string.Format, except that named placeholders accepted as well as numeric placeholders. This method replaces named placeholders with numbers, then calls string.Format.
Named placeholders are useful for communicating information about a placeholder to a human translator. Here is an example:
In some cases a translator might have difficulty translating a phrase without knowing what a numeric placeholder ({0} or {1}) refers to, so a named placeholder can provide an important clue. The localization system is invoked as follows:
The placeholder names are not case sensitive.
You can use numeric placeholders, alignment and formatting codes also:
This method will ignore the first N+1 arguments in args, where {N} is the largest numeric placeholder. It is assumed that the placeholder name ends at the first comma or colon; hence the placeholder in this example is called "dist", not "dist,6:###.00".
If a placeholder name is not found in the argument list then it is not replaced with a number before the call to string.Format, so a FormatException will occur.
References Loyc.StringExt.EliminateNamedArgs().
|
inlinestatic |
Converts a series of values to strings, and concatenates them with a given separator between them.
Join(" + ", new[] { 1,2,3 }) returns "1 + 2 + 3".
This method (but taking IEnumerable{T}) exists in the BCL starting in .NET 4
References Loyc.StringExt.Join().
Referenced by Loyc.StringExt.Join().
|
inlinestatic |
Returns the leftmost 'count' characters of 's', or s itself if count > s.Length.
|
inlinestatic |
Returns the rightmost 'count' characters of 's', or s itself if count > s.Length.
|
inlinestatic |
A variation on String.Substring() that never throws.
This is best explained by examples: "Hi everybody!".SafeSubstring(8, 500) == "body!" "Hi everybody!".SafeSubstring(-3, 5) == "Hi" "Hi everybody!".SafeSubstring(-5, 5) == "" "Hi everybody!".SafeSubstring(8, -5) == "" "Hi everybody!".SafeSubstring(500, 8) == "" "Hi everybody!".SafeSubstring(int.MinValue + 500, int.MaxValue) == "Hi everybody!" ((string)null).SafeSubstring(0, 1) == null
Gets the substrings to the left and right of a dividing character.
s | String to split |
delimiter | Dividing character. |