Programming Reference for VirtualLab Fusion  2026.1
Loading...
Searching...
No Matches
StringSupport Class Reference

This class is subject to change. Programs using this class may require changes with a new version of VirtualLab.
Class containing static methods to create strings formatted in a special way. More...

Static Public Member Functions

static string AddPluralS (int numberOfEntries, string singularString)
 Adds the plural-s to the given string if there are two or more entries and English language is used.
 
static string AddPluralS (string singularString)
 Adds the plural-s to the given string if English language is used.
 
static string ArrayToString (object[] array, string conjunction="and", bool useQuotationMarks=false, bool createList=false)
 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.
 
static string CommonStartStringOfArrayEntries (string[] arrayOfStrings, bool onlyCompleteWords)
 Method which extracts a common string all entries of a string array start with.
 
static string ConcatenateStrings (string[] strings)
 Concatenates the given strings each with a space in between (but in Chinese culture).
 
static string[] ExtractFromFormattedString (string completeString, string formatString, bool removeSpacesInFormatString)
 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.
 
static string ListToString (IList list, string conjunction="and", bool useQuotationMarks=false, bool createList=false)
 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.
 
static string ListToString (string prefix, IList list, string conjunction="and", bool useQuotationMarks=false, bool createList=false)
 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.
 
static string MakeSansSerifBold (string stringToConvert)
 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.
 
static string MoreLegibleVariableName (string variableName)
 Converts the given variable name into a more legible name by applying the following rules.
 
static string PrependTimeStamp (this string stringToConvert)
 This extension method prepends a time stamp to the given string (and appends a line break).
 
static string ReplaceAnyCharacter (this string inputString, string stringToInsert, char[] charactersToReplace)
 Replaces several distinct character of a string by the same character.
 
static string ReplaceAnyString (this string inputString, string stringToInsert, string[] stringsToReplace)
 Replaces several distinct substring of a string by the same string.
 
static string SplitName (string name)
 This method converts variable names into more readable strings by applying the following rules:
 
static IEnumerable< string > SplitToLines (this string input)
 Splits this string into an array with one entry per line.
 
static bool StringContainsAnyPartialString (string stringToCheck, List< string > partialStrings)
 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).
 
static string ToLongDateString_VL (this DateTime date)
 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.
 
static string ToOrdinal (this int number)
 Get the ordinal value of positive integers.
 
static string ToString_VL (this double number, int? numberOfSignificantDigits=null)
 Converts the numeric value of this instance to its equivalent string representation, using the specified number of digits (by default DefaultNumberOfSignificantDigits).
 
static string ToString_VL (this double number, out bool trailingZerosConvertedToDecimalPower, int? numberOfSignificantDigits=null, int? magnitudeThresholdForExponent=null)
 Converts the numeric value of this instance to its equivalent string representation, using the specified number of digits (by default DefaultNumberOfSignificantDigits).
 
static string ToUpperFirstLetter (this string stringToConvert)
 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.
 
static string ToUpperFirstLetters (this string stringToConvert)
 This extension method converts a given string so that the first letter of each word is upper case, all other characters are lower case.
 

Static Public Attributes

const string Back_String
 String to be used for 'Back' buttons in wizards and similar controls.
 
const 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.
 
const string DateTimeFormatISOExtended
 An extended date time format which complies with ISO 8601. The datum is separated by hyphens and time is separated by colons.
 
static readonly CultureInfo 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.
 
static int DefaultNumberOfSignificantDigits
 The default number of significant digits with which double numbers are formatted. Usually the value from the Global Options.
 
const string Finish_String
 String to be used for 'Finish' buttons in wizards and similar controls.
 
const int 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.
 
const string NeverUsedCharacter
 A character which is most likely never used in real-life strings (Tibetian symbol for "8.5").
 
const string Next_String
 String to be used for 'Next' buttons in wizards and similar controls.
 
static readonly string NotApplicableString
 String to be used if a correct meaning is not yet known. (= "N/A")
 
const int 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.
 
const int RecommendedNumberOfSignificantDigits
 The recommended number of digits, for example the predefined value for the DefaultNumberOfSignificantDigits defined by the user.
 
const string 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.
 
const string SpaceReplacement
 "Bottom half o" = ᴗ. Used as replacement for space in variable names.
 
static bool UseIndicatorForHiddenDigits
 If for a physical value some digits where hidden due to rounding, shall a symbol (e.g. "…") indicate this?
 

Properties

static NumberFormatInfo NumberFormat [get]
 Default numerical format.
 

Detailed Description

This class is subject to change. Programs using this class may require changes with a new version of VirtualLab.
Class containing static methods to create strings formatted in a special way.

Member Function Documentation

◆ AddPluralS() [1/2]

static string AddPluralS ( int numberOfEntries,
string singularString )
static

Adds the plural-s to the given string if there are two or more entries and English language is used.

Parameters
numberOfEntriesThe number of entries.
singularStringThe string to which the plural-s shall be added.
Returns
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() [2/2]

static string AddPluralS ( string singularString)
static

Adds the plural-s to the given string if English language is used.

Parameters
singularStringThe string to which the plural-s shall be added.
Returns
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()

static string ArrayToString ( object[] array,
string conjunction = "and",
bool useQuotationMarks = false,
bool createList = false )
static

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.

Parameters
arrayThe 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).
conjunctionThe 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.
useQuotationMarksIf this optional parameter is set to true, each entry is embedded in quotation marks. E. g.: “a”, “b”, or “c”.
createListIf this optional parameter is set to true, the entries are written as a bullet list.
Returns
The formatted string.

◆ CommonStartStringOfArrayEntries()

static string CommonStartStringOfArrayEntries ( string[] arrayOfStrings,
bool onlyCompleteWords )
static

Method which extracts a common string all entries of a string array start with.

Parameters
arrayOfStringsArray of strings to be examined.
onlyCompleteWordstrue: Only complete words are extracted.
Returns
The common string all entries of a string array start with.

◆ ConcatenateStrings()

static string ConcatenateStrings ( string[] strings)
static

Concatenates the given strings each with a space in between (but in Chinese culture).

Parameters
stringsThe strings to concatenate.
Returns
The strings concatenated with spaces.

◆ ExtractFromFormattedString()

static string[] ExtractFromFormattedString ( string completeString,
string formatString,
bool removeSpacesInFormatString )
static

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.

Parameters
completeStringThe complete string which was formatted using the format string.
formatStringThe format string.
removeSpacesInFormatStringSpaces 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
The strings which were formatted using the format string. For "Hello … World" in our example, "Hello" and "World" would be returned.

◆ ListToString() [1/2]

static string ListToString ( IList list,
string conjunction = "and",
bool useQuotationMarks = false,
bool createList = false )
static

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.

Parameters
listThe 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).
conjunctionThe conjunction used if two or more entries are present. "and" by default.
useQuotationMarksIf this optional parameter is set to true, each entry is embedded in quotation marks. E. g.: “a”, “b”, or “c”.
createListIf this optional parameter is set to true, the entries are written as a bullet list.
Returns
The formatted string.

◆ ListToString() [2/2]

static string ListToString ( string prefix,
IList list,
string conjunction = "and",
bool useQuotationMarks = false,
bool createList = false )
static

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.

Parameters
prefixSingle word prepended to the list entries. Maybe a plural-s is added to it.
listThe 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).
conjunctionThe conjunction used if two or more entries are present. "and" by default.
useQuotationMarksIf this optional parameter is set to true, each entry is embedded in quotation marks. E. g.: “a”, “b”, or “c”.
createListIf this optional parameter is set to true, the entries are written as a bullet list.
Returns
The formatted string.

◆ MakeSansSerifBold()

static string MakeSansSerifBold ( string stringToConvert)
static

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.

Parameters
stringToConvertThe 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
The converted string.

◆ MoreLegibleVariableName()

static string MoreLegibleVariableName ( string variableName)
static

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

Parameters
variableNameThe variable name.
Returns
The more legible name, which ca no longer be used as variable name.

◆ PrependTimeStamp()

static string PrependTimeStamp ( this string stringToConvert)
static

This extension method prepends a time stamp to the given string (and appends a line break).

Parameters
stringToConvertThe string to convert. You can use this method also as stringToConvert.PrependTimeStamp().
Returns
The converted string.

◆ ReplaceAnyCharacter()

static string ReplaceAnyCharacter ( this string inputString,
string stringToInsert,
char[] charactersToReplace )
static

Replaces several distinct character of a string by the same character.

Parameters
inputStringThe string where characters shall be replaced.
stringToInsertThe string to insert instead of any of the charactersToReplace.
charactersToReplaceArray of characters each of which is replaced by stringToInsert.
Returns
The changed string.

◆ ReplaceAnyString()

static string ReplaceAnyString ( this string inputString,
string stringToInsert,
string[] stringsToReplace )
static

Replaces several distinct substring of a string by the same string.

Parameters
inputStringThe string where substrings shall be replaced.
stringToInsertThe string to insert instead of any of the stringsToReplace.
stringsToReplaceArray of strings each of which is replaced by stringToInsert.
Returns
The changed string.

◆ SplitName()

static string SplitName ( string name)
static

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

Parameters
nameThe variable name to convert.
Returns
The converted variable name split into single words.

◆ SplitToLines()

static IEnumerable< string > SplitToLines ( this string input)
static

Splits this string into an array with one entry per line.

Parameters
inputThe input string.
Returns
Enumerable of the strings on which you can use LinQ if desired.

◆ StringContainsAnyPartialString()

static bool StringContainsAnyPartialString ( string stringToCheck,
List< string > partialStrings )
static

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

Parameters
stringToCheckThe string to search.
partialStringsList of partial strings.
Returns
True if any of the given partial strings is part of the stringToCheck.

◆ ToLongDateString_VL()

static string ToLongDateString_VL ( this DateTime date)
static

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.

Parameters
dateThe date to convert.
Returns
A string that contains the long date string representation of the current DateTime object.

◆ ToOrdinal()

static string ToOrdinal ( this int number)
static

Get the ordinal value of positive integers.

Parameters
numberThe number.
Returns
Ordinal value of positive integers, or int.ToString() if less than 1.

◆ ToString_VL() [1/2]

static string ToString_VL ( this double number,
int? numberOfSignificantDigits = null )
static

Converts the numeric value of this instance to its equivalent string representation, using the specified number of digits (by default DefaultNumberOfSignificantDigits).

Parameters
numberThe number to format.
numberOfSignificantDigitsThe 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
The string representation of the value of this instance with the given number of significant digits.
Exceptions
System.ArgumentExceptionWrong number of digits used for formatting of a double value.

◆ ToString_VL() [2/2]

static string ToString_VL ( this double number,
out bool trailingZerosConvertedToDecimalPower,
int? numberOfSignificantDigits = null,
int? magnitudeThresholdForExponent = null )
static

Converts the numeric value of this instance to its equivalent string representation, using the specified number of digits (by default DefaultNumberOfSignificantDigits).

Parameters
numberThe number to format.
numberOfSignificantDigitsThe 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.
trailingZerosConvertedToDecimalPowerFlag indicating whether or not trailing zeros has been converted to decimal power.
magnitudeThresholdForExponentFrom 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
The string representation of the value of this instance with the given number of significant digits.
Exceptions
System.ArgumentExceptionWrong number of digits used for formatting of a double value.

◆ ToUpperFirstLetter()

static string ToUpperFirstLetter ( this string stringToConvert)
static

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.

Parameters
stringToConvertThe string to convert. You can use this method also as stringToConvert.ToUpperFirstLetter().
Returns
The converted string.

◆ ToUpperFirstLetters()

static string ToUpperFirstLetters ( this string stringToConvert)
static

This extension method converts a given string so that the first letter of each word is upper case, all other characters are lower case.

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