Enhanced C#
Language of your choice: library documentation
|
Extension methods for strings, such as SplitAt, Left, Right, FormatCore and Slice. More...
Extension methods for strings, such as SplitAt, Left, Right, FormatCore and Slice.
Static Public Member Functions | |
static string | WithoutPrefix (this string s, string prefix, StringComparison mode=StringComparison.Ordinal) |
Returns a version of the string without the specified prefix. If the string does not have the specified prefix, it is returned unchanged. The prefix check is case-sensitive. More... | |
static string | WithoutSuffix (this string s, string suffix, StringComparison mode=StringComparison.Ordinal) |
Returns a version of the string without the specified suffix. If the string does not have the specified suffix, it is returned unchanged. The suffix check is case-sensitive. More... | |
static UString | WithoutPrefix (this UString s, UString prefix, bool ignoreCase=false) |
Returns a version of the string without the specified prefix. If the string does not have the specified prefix, it is returned unchanged. The prefix check is case-sensitive. More... | |
static UString | WithoutSuffix (this UString s, UString suffix, bool ignoreCase=false) |
Returns a version of the string without the specified suffix. If the string does not have the specified suffix, it is returned unchanged. The suffix check is case-sensitive. More... | |
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 bool | Contains (this string s, char c) |
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 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 | Slice (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.
References Loyc.UString.Slice().
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:
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".
Typically, the named arguments are expected to start at index N+1 in the variable argument array, where {N} is the largest numeric placeholder, and if there are no numeric placeholders then the named arguments should begin at index 0. In this example there is a {0}, so the named arguments should start at index 1. However, since named arguments always come in pairs, an extra rule increments the N if the number of remaining arguments starting at N is not an even number. For example, in
There are three args left after the numeric ones, so the first remaining argument is ignored to make it an even number.
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. |
|
static |
Returns a version of the string without the specified prefix. If the string does not have the specified prefix, it is returned unchanged. The prefix check is case-sensitive.
|
static |
Returns a version of the string without the specified prefix. If the string does not have the specified prefix, it is returned unchanged. The prefix check is case-sensitive.
|
static |
Returns a version of the string without the specified suffix. If the string does not have the specified suffix, it is returned unchanged. The suffix check is case-sensitive.