Table of Contents

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

string

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

string

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

string

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

CultureInfo

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

int

Finish_String

String to be used for 'Finish' buttons in wizards and similar controls.

public const string Finish_String = "Finish ⯀"

Field Value

string

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

int

NeverUsedCharacter

A character which is most likely never used in real-life strings (Tibetian symbol for "8.5").

public const string NeverUsedCharacter = "༲"

Field Value

string

Next_String

String to be used for 'Next' buttons in wizards and similar controls.

public const string Next_String = "Next ⯈"

Field Value

string

NotApplicableString

String to be used if a correct meaning is not yet known. (= "N/A")

public static readonly string NotApplicableString

Field Value

string

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

int

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

int

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

string

SpaceReplacement

"Bottom half o" = ᴗ. Used as replacement for space in variable names.

public const string SpaceReplacement = "ᴗ"

Field Value

string

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

bool

Properties

NumberFormat

Default numerical format

public static NumberFormatInfo NumberFormat { get; }

Property Value

NumberFormatInfo

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

numberOfEntries int

The number of entries.

singularString string

The 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

singularString string

The 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

array object[]

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).

conjunction string

The 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.

useQuotationMarks bool

If this optional parameter is set to true, each entry is embedded in quotation marks. E. g.: “a”, “b”, or “c”.

createList bool

If 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

arrayOfStrings string[]

Array of strings to be examined.

onlyCompleteWords bool

true: 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

strings string[]

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

completeString string

The complete string which was formatted using the format string.

formatString string

The format string.

removeSpacesInFormatString bool

Spaces 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

list IList

The 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).

conjunction string

The conjunction used if two or more entries are present. "and" by default.

useQuotationMarks bool

If this optional parameter is set to true, each entry is embedded in quotation marks. E. g.: “a”, “b”, or “c”.

createList bool

If 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

prefix string

Single word prepended to the list entries. Maybe a plural-s is added to it.

list IList

The 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).

conjunction string

The conjunction used if two or more entries are present. "and" by default.

useQuotationMarks bool

If this optional parameter is set to true, each entry is embedded in quotation marks. E. g.: “a”, “b”, or “c”.

createList bool

If 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

stringToConvert string

The 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

variableName string

The 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

stringToConvert string

The 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

inputString string

The string where characters shall be replaced.

stringToInsert string

The string to insert instead of any of the charactersToReplace.

charactersToReplace char[]

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

inputString string

The string where substrings shall be replaced.

stringToInsert string

The string to insert instead of any of the stringsToReplace.

stringsToReplace string[]

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

name string

The 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

input string

The 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

stringToCheck string

The string to search.

partialStrings List<string>

List of partial strings.

Returns

bool

True if 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

date DateTime

The date to convert.

Returns

string

A string that contains the long date string representation of the current DateTime object.

ToOrdinal(int)

Get the ordinal value of positive integers.

public static string ToOrdinal(this int number)

Parameters

number int

The 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

number double

The number to format.

trailingZerosConvertedToDecimalPower bool

Flag indicating whether or not trailing zeros has been converted to decimal power.

numberOfSignificantDigits int?

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.

magnitudeThresholdForExponent int?

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

number double

The number to format.

numberOfSignificantDigits int?

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

stringToConvert string

The 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

stringToConvert string

The string to convert. You can use this method also as stringToConvert.ToUpperFirstLetters().

Returns

string

The converted string.