Class StringSupport
- Namespace
- Wyrowski.Infrastructure.Support
- Assembly
- Wyrowski.Infrastructure.dll
\unstable Class containing static methods to create strings formatted in a special way.
public static class StringSupport
- Inheritance
-
StringSupport
- Inherited Members
Fields
Back_String
String to be used for 'Back' buttons in wizards and similar controls.
public const string Back_String = "⯇ Back"
Field Value
DateTimeFormatISOBasic
A basic date time format which complies with ISO 8601. It avoids ":" (as separator of time units) and "/" (date unit separator in several cultures) and thus should be used for file names.
public const string DateTimeFormatISOBasic = "yyyy-MM-ddTHHmmss"
Field Value
DateTimeFormatISOExtended
An extended date time format which complies with ISO 8601. The datum is separated by hyphens and time is separated by colons.
public const string DateTimeFormatISOExtended = "yyyy-MM-dd HH:mm:ss"
Field Value
DefaultCulture
The default culture used for string formatting. It is the "en-US" culture with a dot as decimal separator and a thin space as number group separator.
public static readonly CultureInfo DefaultCulture
Field Value
DefaultNumberOfSignificantDigits
The default number of significant digits with which double numbers are formatted. Usually the value from the Global Options.
public static int DefaultNumberOfSignificantDigits
Field Value
Finish_String
String to be used for 'Finish' buttons in wizards and similar controls.
public const string Finish_String = "Finish ⯀"
Field Value
MaximumNumberOfSignificantDigits
The absolute maximum number of significant digits for double values. Should only be used for export of numbers to other programs. Note that https://learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-double states that for doubles there are only 15 digits of precision for anyhow.
public const int MaximumNumberOfSignificantDigits = 17
Field Value
NeverUsedCharacter
A character which is most likely never used in real-life strings (Tibetian symbol for "8.5").
public const string NeverUsedCharacter = "༲"
Field Value
Next_String
String to be used for 'Next' buttons in wizards and similar controls.
public const string Next_String = "Next ⯈"
Field Value
NotApplicableString
String to be used if a correct meaning is not yet known. (= "N/A")
public static readonly string NotApplicableString
Field Value
RecommendedMaximumNumberOfSignificantDigits
Maximal Number of decimal digits recommended for the formatting as string of a physical value or another value with a unit. More digits can usually not measured anyhow. If the user enters a higher value in the Global Options dialog, display of numbers may be truncated in some dialogs.
public const int RecommendedMaximumNumberOfSignificantDigits = 10
Field Value
RecommendedNumberOfSignificantDigits
The recommended number of digits, for example the predefined value for the DefaultNumberOfSignificantDigits defined by the user.
public const int RecommendedNumberOfSignificantDigits = 5
Field Value
SortCharacter
If you add this character at the beginning of a string, it is sorted before any "normal" strings. This character is a zero-width space.
public const string SortCharacter = ""
Field Value
SpaceReplacement
"Bottom half o" = ᴗ. Used as replacement for space in variable names.
public const string SpaceReplacement = "ᴗ"
Field Value
UseIndicatorForHiddenDigits
If for a physical value some digits where hidden due to rounding, shall a symbol (e.g. "…") indicate this?
public static bool UseIndicatorForHiddenDigits
Field Value
Properties
NumberFormat
Default numerical format
public static NumberFormatInfo NumberFormat { get; }
Property Value
Methods
AddPluralS(int, string)
Adds the plural-s to the given string if there are two or more entries and English language is used.
public static string AddPluralS(int numberOfEntries, string singularString)
Parameters
numberOfEntriesintThe number of entries.
singularStringstringThe string to which the plural-s shall be added.
Returns
- string
The singular string if there are less than two entries. The singular string + "s" in normal case, the singular string ending with "ies" for words ending with "y". Irregular forms are not yet considered.
AddPluralS(string)
Adds the plural-s to the given string if English language is used.
public static string AddPluralS(string singularString)
Parameters
singularStringstringThe string to which the plural-s shall be added.
Returns
- string
The singular string + "s" in normal case, the singular string ending with "ies" for words ending with "y". Irregular forms are not yet considered.
ArrayToString(object[], string, bool, bool)
Converts the given array to a string containing all individual members. E.g. something like "a", "a and b", and "a, b, and c" (for one two or three entries in the array respectively.
public static string ArrayToString(object[] array, string conjunction = "and", bool useQuotationMarks = false, bool createList = false)
Parameters
arrayobject[]The array to convert. If you want apply special formatting first convert the array of objects to an array of strings (formatted as you want it).
conjunctionstringThe conjunction used if two or more entries are present. "and" by default. Can also be empty if you do not want to use a conjunction.
useQuotationMarksboolIf this optional parameter is set to
true, each entry is embedded in quotation marks. E. g.: “a”, “b”, or “c”.createListboolIf this optional parameter is set to
true, the entries are written as a bullet list.
Returns
- string
The formatted string.
CommonStartStringOfArrayEntries(string[], bool)
Method which extracts a common string all entries of a string array start with.
public static string CommonStartStringOfArrayEntries(string[] arrayOfStrings, bool onlyCompleteWords)
Parameters
arrayOfStringsstring[]Array of strings to be examined.
onlyCompleteWordsbooltrue: Only complete words are extracted.
Returns
- string
The common string all entries of a string array start with.
ConcatenateStrings(params string[])
Concatenates the given strings each with a space in between (but in Chinese culture).
public static string ConcatenateStrings(params string[] strings)
Parameters
stringsstring[]The strings to concatenate.
Returns
- string
The strings concatenated with spaces.
ExtractFromFormattedString(string, string, bool)
If a string was formatted e.g. with the format string "{0} … {1}", this method extracts the original strings which were placed in the place holders {0} and {1}. This method only works if the strings between the original strings are not contained in the original strings. E.g. if you put "0 … 1" and "2" in the aforementioned format string, you obtain "0 … 1 … 2" which cannot be converted back properly.
public static string[] ExtractFromFormattedString(string completeString, string formatString, bool removeSpacesInFormatString)
Parameters
completeStringstringThe complete string which was formatted using the format string.
formatStringstringThe format string.
removeSpacesInFormatStringboolSpaces before the curly brackets in the format string are removed. In this way, for something like "0…1" parsing to integers works if the format string is "{0} … {1}".
Returns
- string[]
The strings which were formatted using the format string. For "Hello … World" in our example, "Hello" and "World" would be returned.
ListToString(IList, string, bool, bool)
Converts the given list to a string containing all individual members. E.g. something like "a", "a and b", and "a, b, and c" (for one two or three entries in the list respectively.
public static string ListToString(IList list, string conjunction = "and", bool useQuotationMarks = false, bool createList = false)
Parameters
listIListThe list to convert. If you want apply special formatting first convert the list of objects to an array or list of strings (formatted as you want it).
conjunctionstringThe conjunction used if two or more entries are present. "and" by default.
useQuotationMarksboolIf this optional parameter is set to
true, each entry is embedded in quotation marks. E. g.: “a”, “b”, or “c”.createListboolIf this optional parameter is set to
true, the entries are written as a bullet list.
Returns
- string
The formatted string.
ListToString(string, IList, string, bool, bool)
Converts the given list to a string containing all individual members. E.g. something like "a", "a and b", and "a, b, and c" (for one two or three entries in the list respectively.
public static string ListToString(string prefix, IList list, string conjunction = "and", bool useQuotationMarks = false, bool createList = false)
Parameters
prefixstringSingle word prepended to the list entries. Maybe a plural-s is added to it.
listIListThe list to convert. If you want apply special formatting first convert the list of objects to an array or list of strings (formatted as you want it).
conjunctionstringThe conjunction used if two or more entries are present. "and" by default.
useQuotationMarksboolIf this optional parameter is set to
true, each entry is embedded in quotation marks. E. g.: “a”, “b”, or “c”.createListboolIf this optional parameter is set to
true, the entries are written as a bullet list.
Returns
- string
The formatted string.
MakeSansSerifBold(string)
Writes the given string in sans-serif bold letters. To this end the Unicode block "Mathematical Alphanumeric Symbols" (https://en.wikipedia.org/wiki/Mathematical_Alphanumeric_Symbols) is used. Thus the result might not look completely as desired and this method should only used for to emphasize short portions of text.
public static string MakeSansSerifBold(string stringToConvert)
Parameters
stringToConvertstringThe string to convert. Only the standard Latin letters 'A' to 'Z' and 'a' to 'z' as well as digits are supported, other characters remain unchanged.
Returns
- string
The converted string.
MoreLegibleVariableName(string)
Converts the given variable name into a more legible name by applying the following rules.
- "__" (double underscore) is replaced by "-"
- "ᴗ" is replaced by a space.
Examples: "FMMᴗSampling" → "FMM Sampling"; "x__Range" → "x-Range".
public static string MoreLegibleVariableName(string variableName)
Parameters
variableNamestringThe variable name.
Returns
- string
The more legible name, which ca no longer be used as variable name.
PrependTimeStamp(string)
This extension method prepends a time stamp to the given string (and appends a line break).
public static string PrependTimeStamp(this string stringToConvert)
Parameters
stringToConvertstringThe string to convert. You can use this method also as stringToConvert.PrependTimeStamp().
Returns
- string
The converted string.
ReplaceAnyCharacter(string, string, params char[])
Replaces several distinct character of a string by the same character.
public static string ReplaceAnyCharacter(this string inputString, string stringToInsert, params char[] charactersToReplace)
Parameters
inputStringstringThe string where characters shall be replaced.
stringToInsertstringThe string to insert instead of any of the charactersToReplace.
charactersToReplacechar[]Array of characters each of which is replaced by stringToInsert.
Returns
- string
The changed string.
ReplaceAnyString(string, string, params string[])
Replaces several distinct substring of a string by the same string.
public static string ReplaceAnyString(this string inputString, string stringToInsert, params string[] stringsToReplace)
Parameters
inputStringstringThe string where substrings shall be replaced.
stringToInsertstringThe string to insert instead of any of the stringsToReplace.
stringsToReplacestring[]Array of strings each of which is replaced by stringToInsert.
Returns
- string
The changed string.
SplitName(string)
This method converts variable names into more readable strings by applying the following rules:
- "_" is replaced by "-"
- If there are "ᴗ" in the string these symbols are replaced by spaces and the resulting string is returned.
- Else a space is inserted before any uppercase character prepended by a character which is not "-" or "_".
Examples: "JustAnOtherTest" → "Just An Other Test"; "FMMᴗSampling" → "FMM Sampling"; "x_Range" → "x-Range".
public static string SplitName(string name)
Parameters
namestringThe variable name to convert.
Returns
- string
The converted variable name split into single words.
SplitToLines(string)
Splits this string into an array with one entry per line.
public static IEnumerable<string> SplitToLines(this string input)
Parameters
inputstringThe input string.
Returns
- IEnumerable<string>
Enumerable of the strings on which you can use LinQ if desired.
StringContainsAnyPartialString(string, List<string>)
This method determines whether the given string contains any of the given partial strings. If the search should be case insensitive, both parameters should be passed as uppercase (or lowercase).
public static bool StringContainsAnyPartialString(string stringToCheck, List<string> partialStrings)
Parameters
Returns
- bool
Trueif any of the given partial strings is part of the stringToCheck.
ToLongDateString_VL(DateTime)
Converts the value of the current DateTime object to its equivalent long date string representation. In contrast to the .Net implementation, this considers the current UI language and contains a fix for Chinese dates.
public static string ToLongDateString_VL(this DateTime date)
Parameters
dateDateTimeThe date to convert.
Returns
ToOrdinal(int)
Get the ordinal value of positive integers.
public static string ToOrdinal(this int number)
Parameters
numberintThe number.
Returns
- string
Ordinal value of positive integers, or ToString() if less than 1.
ToString_VL(double, out bool, int?, int?)
Converts the numeric value of this instance to its equivalent string representation, using the specified number of digits (by default DefaultNumberOfSignificantDigits).
public static string ToString_VL(this double number, out bool trailingZerosConvertedToDecimalPower, int? numberOfSignificantDigits = null, int? magnitudeThresholdForExponent = null)
Parameters
numberdoubleThe number to format.
trailingZerosConvertedToDecimalPowerboolFlag indicating whether or not trailing zeros has been converted to decimal power.
numberOfSignificantDigitsint?The number of significant digits. Must be between 1 and 17 (inclusive). If this optional parameter is omitted, the value of DefaultNumberOfSignificantDigits is used, which is usually the value from the Global Options.
magnitudeThresholdForExponentint?From which magnitude a number shall be written with exponent? Example: 10'000 will be written as '1e+4' if this parameter is less than or equal to 4.
Returns
- string
The string representation of the value of this instance with the given number of significant digits.
Exceptions
- ArgumentException
Wrong number of digits used for formatting of a double value.
ToString_VL(double, int?)
Converts the numeric value of this instance to its equivalent string representation, using the specified number of digits (by default DefaultNumberOfSignificantDigits).
public static string ToString_VL(this double number, int? numberOfSignificantDigits = null)
Parameters
numberdoubleThe number to format.
numberOfSignificantDigitsint?The number of significant digits. Must be between 1 and 17 (inclusive). If this optional parameter is omitted, the value of DefaultNumberOfSignificantDigits is used, which is usually the value from the Global Options.
Returns
- string
The string representation of the value of this instance with the given number of significant digits.
Exceptions
- ArgumentException
Wrong number of digits used for formatting of a double value.
ToUpperFirstLetter(string)
This extension method converts a given string so that the first letter of the first word is upper case, all other characters are lower case.
public static string ToUpperFirstLetter(this string stringToConvert)
Parameters
stringToConvertstringThe string to convert. You can use this method also as stringToConvert.ToUpperFirstLetter().
Returns
- string
The converted string.
ToUpperFirstLetters(string)
This extension method converts a given string so that the first letter of each word is upper case, all other characters are lower case.
public static string ToUpperFirstLetters(this string stringToConvert)
Parameters
stringToConvertstringThe string to convert. You can use this method also as stringToConvert.ToUpperFirstLetters().
Returns
- string
The converted string.