Class CultureDataFormatter
This is a helper class designed to encode, parse and reformat culturally sensitive data types between an application server without culture knowledge, and a front-end with such knowledge.
Inheritance
Inherited Members
Namespace: SuperOffice.CRM.Globalization
Assembly: SuperOffice.Plugins.dll
Syntax
public static class CultureDataFormatter
Remarks
This class is split between the SuperOffice.Plugins and SuperOffice.Plugins.Shared Most of the functionality lives in SuperOffice.Plugins.Shared, this file will contain methods that are not portable because of references to Stream This PLUGINS.DLL class duplicates the implementation of SOCORE.DLL SuperOffice.CRM.Globalization.CultureDataFormatter
The problem: The application server does not know the culture of the current client. At the same time, we need to be able to include culturally sensitive data (such as a date) as part of a tooltip or other server-side generated text. Before displaying this text to the user, culturally sensitive elements need to be parsed and reformatted to the correct culture.
The methods in this class take care of both sides of this process. The Encode methods, such as EncodeDate(DateTime), take a native data type as input and return a string that contains both a specification of what it is (a date) and the value formatted in the invariant culture.
The LocalizeEncoded(String) method will take such a formatted element, and by calling on the proper LocalFormat method (such as LocalFormatDate(DateTime), return it in its correct form according to the current culture settings for the thread.
Fields
BeginTag
Declaration
public const string BeginTag = "["
Field Value
Type | Description |
---|---|
System.String |
BinaryMarker
Declaration
public const string BinaryMarker = "B"
Field Value
Type | Description |
---|---|
System.String |
DateMarker
Declaration
public const string DateMarker = "D"
Field Value
Type | Description |
---|---|
System.String |
DateTimeMarker
Declaration
public const string DateTimeMarker = "DT"
Field Value
Type | Description |
---|---|
System.String |
DoubleMarker
Declaration
public const string DoubleMarker = "F"
Field Value
Type | Description |
---|---|
System.String |
EndTag
Declaration
public const string EndTag = "]"
Field Value
Type | Description |
---|---|
System.String |
IntArrMarker
Declaration
public const string IntArrMarker = "A"
Field Value
Type | Description |
---|---|
System.String |
IntMarker
Declaration
public const string IntMarker = "I"
Field Value
Type | Description |
---|---|
System.String |
MarkerSeparator
Declaration
public const char MarkerSeparator = ':'
Field Value
Type | Description |
---|---|
System.Char |
MoneyMarker
Declaration
public const string MoneyMarker = "M"
Field Value
Type | Description |
---|---|
System.String |
TimeMarker
Declaration
public const string TimeMarker = "T"
Field Value
Type | Description |
---|---|
System.String |
TimeSpanMarker
Declaration
public const string TimeSpanMarker = "TS"
Field Value
Type | Description |
---|---|
System.String |
Methods
AddColon(String)
Add a colon to a string if it was not already there, strip any whitespace
Declaration
public static string AddColon(string label)
Parameters
Type | Name | Description |
---|---|---|
System.String | label | String to process |
Returns
Type | Description |
---|---|
System.String | Original string, now guaranteed to end in exactly one colon |
AddTerminator(String, String)
Add a terminator to a string. The string is first stripped, then the terminator is added at the end with no whitespace.
Declaration
public static string AddTerminator(string label, string terminator)
Parameters
Type | Name | Description |
---|---|---|
System.String | label | String to process |
System.String | terminator | Terminator to add |
Returns
Type | Description |
---|---|
System.String | String, now ending with terminator and no white space |
CompareEncoded(String, String)
Compare two encoded strings, by parsing them into their underlying data datatype and comparing those
Declaration
public static int CompareEncoded(string x, string y)
Parameters
Type | Name | Description |
---|---|---|
System.String | x | Formatted string |
System.String | y | Formatted string |
Returns
Type | Description |
---|---|
System.Int32 | -1, 0 or 1 depending on the ordering relation between x and y |
Encode(Object)
Encode a object based on type. Types supported: DateTime, Double, Integer, String and Boolean
Declaration
public static string Encode(object value)
Parameters
Type | Name | Description |
---|---|---|
System.Object | value | Object to be encoded |
Returns
Type | Description |
---|---|
System.String | Encoded object |
EncodeBinary(Stream)
Encode a block of binary data, such as an image
Declaration
public static string EncodeBinary(Stream data)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | data | DateTime whose date component is to be encoded |
Returns
Type | Description |
---|---|
System.String | Encoded date |
EncodeBinary(Stream, Boolean)
Encode a block of binary data, such as an image
Declaration
public static string EncodeBinary(Stream data, bool performEncode)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | data | Stream be encoded |
Boolean | performEncode | If true, the input parameter is encoded to string. If false, an empty string is returned instead. This parameter is implemented to streamline coding of optimized field population in the archive providers, where a mode switch may eliminate the need for string-encoded display values. |
Returns
Type | Description |
---|---|
System.String | Encoded date |
EncodeBinaryNoTags(Stream)
Declaration
public static string EncodeBinaryNoTags(Stream data)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | data |
Returns
Type | Description |
---|---|
System.String |
EncodeDate(DateTime)
Encode a date, without a time part
Declaration
public static string EncodeDate(DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | DateTime whose date component is to be encoded |
Returns
Type | Description |
---|---|
System.String | Encoded date |
EncodeDate(DateTime, Boolean)
Encode a date, without a time part. Optionally skip encoding and return an empty string instead.
Declaration
public static string EncodeDate(DateTime dateTime, bool performEncode)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | DateTime whose date component is to be encoded |
Boolean | performEncode | If true, the input parameter is encoded to string. If false, an empty string is returned instead. This parameter is implemented to streamline coding of optimized field population in the archive providers, where a mode switch may eliminate the need for string-encoded display values. |
Returns
Type | Description |
---|---|
System.String | Encoded date |
EncodeDateTime(DateTime)
Encode a date, with a time part.
Declaration
public static string EncodeDateTime(DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | DateTime whose date and time components are to be encoded |
Returns
Type | Description |
---|---|
System.String | Encoded date/time |
EncodeDateTime(DateTime, Boolean)
Encode a date, with a time part. Optionally skip encoding and return an empty string instead.
Declaration
public static string EncodeDateTime(DateTime dateTime, bool performEncode)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | DateTime whose date and time components are to be encoded |
Boolean | performEncode | If true, the input parameter is encoded to string. If false, an empty string is returned instead. This parameter is implemented to streamline coding of optimized field population in the archive providers, where a mode switch may eliminate the need for string-encoded display values. |
Returns
Type | Description |
---|---|
System.String | Encoded date/time |
EncodeDouble(Double)
Encode a double (decimal value). On localization, the default number of decimal digits will be used. Also note that currency amounts should use the EncodeMoney method, if the cultural settings for money are to be taken into account (though the currency symbol is NOT used in localization, because we may be displaying non-native currencies).
Declaration
public static string EncodeDouble(double val)
Parameters
Type | Name | Description |
---|---|---|
System.Double | val | Value to be encoded |
Returns
Type | Description |
---|---|
System.String | Encoded value |
EncodeDouble(Double, Boolean)
Encode a double (decimal value). On localization, the default number of decimal digits will be used. Also note that currency amounts should use the EncodeMoney method, if the cultural settings for money are to be taken into account (though the currency symbol is NOT used in localization, because we may be displaying non-native currencies). Optionally skip encoding and return an empty string instead.
Declaration
public static string EncodeDouble(double val, bool performEncode)
Parameters
Type | Name | Description |
---|---|---|
System.Double | val | Value to be encoded |
Boolean | performEncode | If true, the input parameter is encoded to string. If false, an empty string is returned instead. This parameter is implemented to streamline coding of optimized field population in the archive providers, where a mode switch may eliminate the need for string-encoded display values. |
Returns
Type | Description |
---|---|
System.String | Encoded value |
EncodeDouble(Double, Int32)
Encode a double (decimal value), with the given number of decimals. Note that the full precision is included here, but rounded to the given number of decimals on (re)localization. Also note that currency amounts should use the EncodeMoney method, if the cultural settings for money are to be taken into account (though the currency symbol is NOT used in localization, because we may be displaying non-native currencies, saying $ when it's actually € or NOK is silly).
Declaration
public static string EncodeDouble(double val, int decimals)
Parameters
Type | Name | Description |
---|---|---|
System.Double | val | Value to be encoded |
System.Int32 | decimals | Final desired number of decimals |
Returns
Type | Description |
---|---|
System.String | Encoded value |
EncodeDouble(Double, Int32, Boolean)
Encode a double (decimal value), with the given number of decimals. Note that the full precision is included here, but rounded to the given number of decimals on (re)localization. Also note that currency amounts should use the EncodeMoney method, if the cultural settings for money are to be taken into account (though the currency symbol is NOT used in localization, because we may be displaying non-native currencies, saying $ when it's actually € or NOK is silly). Optionally skip encoding and return an empty string instead.
Declaration
public static string EncodeDouble(double val, int decimals, bool performEncode)
Parameters
Type | Name | Description |
---|---|---|
System.Double | val | Value to be encoded |
System.Int32 | decimals | Final desired number of decimals |
Boolean | performEncode | If true, the input parameter is encoded to string. If false, an empty string is returned instead. This parameter is implemented to streamline coding of optimized field population in the archive providers, where a mode switch may eliminate the need for string-encoded display values. |
Returns
Type | Description |
---|---|
System.String | Encoded value |
EncodeInt(Int32)
Encode an integer. Integers are usually not culturally sensitive... but who knows.
Declaration
public static string EncodeInt(int val)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | val | Value to encode |
Returns
Type | Description |
---|---|
System.String | Encoded value |
EncodeInt(Int32, Boolean)
Encode an integer. Integers are usually not culturally sensitive... but who knows. Optionally skip encoding and return an empty string instead.
Declaration
public static string EncodeInt(int val, bool performEncode)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | val | Value to encode |
Boolean | performEncode | If true, the input parameter is encoded to string. If false, an empty string is returned instead. This parameter is implemented to streamline coding of optimized field population in the archive providers, where a mode switch may eliminate the need for string-encoded display values. |
Returns
Type | Description |
---|---|
System.String | Encoded value |
EncodeIntArr(Int32[])
Declaration
public static string EncodeIntArr(params int[] intArr)
Parameters
Type | Name | Description |
---|---|---|
System.Int32[] | intArr |
Returns
Type | Description |
---|---|
System.String |
EncodeMoney(Double)
Encode a double, for displaying it as money. The local user settings for currency, EXCEPT the currency symbol, will be used for display. No currency symbol will be display regardless of settings.
Declaration
public static string EncodeMoney(double val)
Parameters
Type | Name | Description |
---|---|---|
System.Double | val | Value to encode |
Returns
Type | Description |
---|---|
System.String | Encoded value |
EncodeMoney(Double, Boolean)
Encode a double, for displaying it as money. The local user settings for currency, EXCEPT the currency symbol, will be used for display. No currency symbol will be display regardless of settings. Optionally skip encoding and return an empty string instead.
Declaration
public static string EncodeMoney(double val, bool performEncode)
Parameters
Type | Name | Description |
---|---|---|
System.Double | val | Value to encode |
Boolean | performEncode | If true, the input parameter is encoded to string. If false, an empty string is returned instead. This parameter is implemented to streamline coding of optimized field population in the archive providers, where a mode switch may eliminate the need for string-encoded display values. |
Returns
Type | Description |
---|---|
System.String | Encoded value |
EncodeTime(DateTime)
Encode a time, without a date part
Declaration
public static string EncodeTime(DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | DateTime whose time component is to be encoded |
Returns
Type | Description |
---|---|
System.String | Encoded time |
EncodeTime(DateTime, Boolean)
Encode a time, without a date part. Optionally skip encoding and return an empty string instead.
Declaration
public static string EncodeTime(DateTime dateTime, bool performEncode)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | DateTime whose time component is to be encoded |
Boolean | performEncode | If true, the input parameter is encoded to string. If false, an empty string is returned instead. This parameter is implemented to streamline coding of optimized field population in the archive providers, where a mode switch may eliminate the need for string-encoded display values. |
Returns
Type | Description |
---|---|
System.String | Encoded time |
EncodeTimeSpan(Int32, Boolean)
Encode a timespan Optionally skip encoding and return an empty string instead.
Declaration
public static string EncodeTimeSpan(int seconds, bool performEncode = true)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | seconds | Seconds to be encoded. |
Boolean | performEncode | If true, the input parameter is encoded to string. If false, an empty string is returned instead. This parameter is implemented to streamline coding of optimized field population in the archive providers, where a mode switch may eliminate the need for string-encoded display values. |
Returns
Type | Description |
---|---|
System.String | Encoded time |
EncodeTimeSpan(TimeSpan, Boolean)
Encode a timespan, encodes total number of seconds Optionally skip encoding and return an empty string instead.
Declaration
public static string EncodeTimeSpan(TimeSpan timeSpan, bool performEncode = true)
Parameters
Type | Name | Description |
---|---|---|
System.TimeSpan | timeSpan | TimeSpan to be encoded. |
Boolean | performEncode | If true, the input parameter is encoded to string. If false, an empty string is returned instead. This parameter is implemented to streamline coding of optimized field population in the archive providers, where a mode switch may eliminate the need for string-encoded display values. |
Returns
Type | Description |
---|---|
System.String | Encoded time |
FormatFromMetadata(String, FieldMetadataInfo)
Declaration
public static string FormatFromMetadata(string input, FieldMetadataInfo typeInfo)
Parameters
Type | Name | Description |
---|---|---|
System.String | input | |
FieldMetadataInfo | typeInfo |
Returns
Type | Description |
---|---|
System.String |
GetStringType(String, out String, out Int32)
Declaration
public static string GetStringType(string encodedSomething, out string val, out int decimals)
Parameters
Type | Name | Description |
---|---|---|
System.String | encodedSomething | |
System.String | val | |
System.Int32 | decimals |
Returns
Type | Description |
---|---|
System.String |
GetSuperOfficeLanguages()
Get all current supported superoffice languages, by superoffice language code (win legacy)
Declaration
public static IEnumerable<string> GetSuperOfficeLanguages()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.String> |
LocalFormatDate(DateTime)
Format a date (without time) according to current settings
Declaration
public static string LocalFormatDate(DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | DateTime to be formatted |
Returns
Type | Description |
---|---|
System.String | Formatted date |
LocalFormatDateTime(DateTime)
Format a date with time according to current settings
Declaration
public static string LocalFormatDateTime(DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | Datetime to be formatted |
Returns
Type | Description |
---|---|
System.String | Formatted date and time |
LocalFormatDouble(Double, Int32)
Format a double, with the given number of decimal digits; otherwise the current settings will be followed
Declaration
public static string LocalFormatDouble(double val, int decimals)
Parameters
Type | Name | Description |
---|---|---|
System.Double | val | Double to be formatted |
System.Int32 | decimals | Desired number of decimals |
Returns
Type | Description |
---|---|
System.String | Formatted number |
LocalFormatInt(Int32)
Format an integer according to current settings
Declaration
public static string LocalFormatInt(int val)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | val | int to be formatted |
Returns
Type | Description |
---|---|
System.String | Formatted integer |
LocalFormatLongDate(DateTime)
Format a long date (without time) according to current settings
Declaration
public static string LocalFormatLongDate(DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | DateTime to be formatted |
Returns
Type | Description |
---|---|
System.String | Formatted long date |
LocalFormatLongDateTime(DateTime)
Format a long date with a short time according to current settings
Declaration
public static string LocalFormatLongDateTime(DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | Datetime to be formatted |
Returns
Type | Description |
---|---|
System.String | Formatted long date and short time |
LocalFormatMoney(Double)
Format a double as a currency value, though without a currency symbol. Other local settings for currencies will be followed.
Declaration
public static string LocalFormatMoney(double val)
Parameters
Type | Name | Description |
---|---|---|
System.Double | val | Double to be formatted |
Returns
Type | Description |
---|---|
System.String | Formatted amount |
LocalFormatTime(DateTime)
Format a time without date according to current settings
Declaration
public static string LocalFormatTime(DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | DateTime to be formatted |
Returns
Type | Description |
---|---|
System.String | Formatted time, without date |
LocalizeEncoded(String)
Take an encoded value of any type, parse it, and reformat it to its localized (current culture) string form
Declaration
public static string LocalizeEncoded(string encodedSomething)
Parameters
Type | Name | Description |
---|---|---|
System.String | encodedSomething | Output from one of the Encode methods |
Returns
Type | Description |
---|---|
System.String | Equivalent, localized value |
MapCsLanguageToSuperOfficeLanguage(String)
Convert a language code from cs to SuperOffice language code.
Declaration
public static string MapCsLanguageToSuperOfficeLanguage(string csLang)
Parameters
Type | Name | Description |
---|---|---|
System.String | csLang |
Returns
Type | Description |
---|---|
System.String | SuperOffice languagecode or string.empty if none found |
MapCultureToSuperOfficeLanguage(String)
Converts .net Culture name ("sv-SE") to SuperOffice language code ("SW").
Declaration
public static string MapCultureToSuperOfficeLanguage(string cultureName)
Parameters
Type | Name | Description |
---|---|---|
System.String | cultureName | Either a culture name or a SuperOffice language code. |
Returns
Type | Description |
---|---|
System.String | A SuperOffice language code. (US, NO, SW, DA, FI, FR, GE, IT, NL, SP, PL, RU, CN, CZ) |
Remarks
Converting to a SuperOffice language code twice is harmless.
If unable to determine a mapping, the default is US (English).
See also MSDN on culture codes.
See Also
MapLanguageToCsLanguage(String)
Convert a language code to the language code expected by CS.
Declaration
public static string MapLanguageToCsLanguage(string languageCode)
Parameters
Type | Name | Description |
---|---|---|
System.String | languageCode |
Returns
Type | Description |
---|---|
System.String |
MapLCIDToSuperOfficeLanguage(Int32)
Converts a .net culture LCID to SuperOffice Language Code
Declaration
public static string MapLCIDToSuperOfficeLanguage(int lcid)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | lcid | The LCID to convert |
Returns
Type | Description |
---|---|
System.String | The SuperOffice language code if defined - the two letter iso name if undefined |
MapSuperOfficeLanguageToCulture(String)
Converts a SuperOffice language code ("SW") to a neutral .net culture name ("sv")
Declaration
public static string MapSuperOfficeLanguageToCulture(string SuperOfficeLanguageCode)
Parameters
Type | Name | Description |
---|---|---|
System.String | SuperOfficeLanguageCode | SuperOffice language code. (US, NO, SW, DA, FI, FR, GE, IT, NL, SP, PL, RU, CN, CZ) |
Returns
Type | Description |
---|---|
System.String | .net neutral Culture name, or empty string (invariant culture) if no mapping found |
Remarks
If unable to determine a mapping, the default is US (English).
See also MSDN on culture codes.
See Also
ParseEncoded(String)
Inspect the marker and parse the content, returning a strongly typed object (double, int, byte[], DateTime etc)
Declaration
public static object ParseEncoded(string encodedSomething)
Parameters
Type | Name | Description |
---|---|---|
System.String | encodedSomething |
Returns
Type | Description |
---|---|
System.Object |
ParseEncodedBinary(String)
Parse/decode an encoded binary data block - either with a marker, or just a Base64 encoded string
Declaration
public static byte[] ParseEncodedBinary(string encodedBinary)
Parameters
Type | Name | Description |
---|---|---|
System.String | encodedBinary |
Returns
Type | Description |
---|---|
System.Byte[] |
ParseEncodedDate(String)
Declaration
public static DateTime ParseEncodedDate(string encodedDate)
Parameters
Type | Name | Description |
---|---|---|
System.String | encodedDate |
Returns
Type | Description |
---|---|
System.DateTime |
ParseEncodedDecimal(String)
Parse "123.4" and "[F:123.4]" into 123.4
Declaration
public static decimal ParseEncodedDecimal(string encodedDecimal)
Parameters
Type | Name | Description |
---|---|---|
System.String | encodedDecimal | "123.4" or "[F:123.4]" |
Returns
Type | Description |
---|---|
System.Decimal | The value or an exception if not a decimal |
ParseEncodedDouble(String)
Parse "123.4" and "[F:123.4]" into 123.4
Declaration
public static double ParseEncodedDouble(string encodedDouble)
Parameters
Type | Name | Description |
---|---|---|
System.String | encodedDouble | "123.4" or "[F:123.4]" |
Returns
Type | Description |
---|---|
System.Double | The value or an exception if not an double |
ParseEncodedInt(String)
Parse "123" and "[I:123]" into 123. Parse "abc" into 0. Does not throw, but returns 0.
Declaration
public static int ParseEncodedInt(string encodedInt)
Parameters
Type | Name | Description |
---|---|---|
System.String | encodedInt | "123" or "[I:123]" |
Returns
Type | Description |
---|---|
System.Int32 | The value as int, or 0 if not an integer |
ParseEncodedInt(String, Boolean)
Parse "123" and "[I:123]" into 123.
Declaration
public static int ParseEncodedInt(string encodedInt, bool strictly)
Parameters
Type | Name | Description |
---|---|---|
System.String | encodedInt | "123" or "[I:123]" |
Boolean | strictly | If true, then throws instead of returning 0 for non-numbers |
Returns
Type | Description |
---|---|
System.Int32 | The value or an exception if not an integer |
ParseEncodedIntArr(String)
Declaration
public static int[] ParseEncodedIntArr(string encodedIntArr)
Parameters
Type | Name | Description |
---|---|---|
System.String | encodedIntArr |
Returns
Type | Description |
---|---|
System.Int32[] |
ParseEncodedTimeSpan(String, Boolean)
Declaration
public static int ParseEncodedTimeSpan(string encodedTimeSpan, bool strictly = false)
Parameters
Type | Name | Description |
---|---|---|
System.String | encodedTimeSpan | |
Boolean | strictly |
Returns
Type | Description |
---|---|
System.Int32 |
ParseInlineElements(String, String)
Parses a resource string with inline culture-sensitive data in the text, for instance dates... provided they have been encoded using the CultureDataFormatter in the first place. Multi-language elements are also handled, before any culture-sensitive elements.
Declaration
public static string ParseInlineElements(string resourceString, string cultureName)
Parameters
Type | Name | Description |
---|---|---|
System.String | resourceString | The string to parse |
System.String | cultureName | The cultureName, typically en-US, nb-NO, but also US, NO is accepted |
Returns
Type | Description |
---|---|
System.String | Parsed resource string. |
ParseInlineMultiLanguageString(String, String, Int32)
Parses the string for multilang strings and uses ParseMultiLanguageString(String, String) to translate the fragment to a culture specific string part
Declaration
public static string ParseInlineMultiLanguageString(string multilangString, string cultureName, int startingIndex = 0)
Parameters
Type | Name | Description |
---|---|---|
System.String | multilangString | The multilanguage string to parse:
|
System.String | cultureName | The cultureName, typically en-US, nb-NO, but also US, NO is accepted |
System.Int32 | startingIndex | The starting index for the parsing |
Returns
Type | Description |
---|---|
System.String | All culture specific string parts translated, or original string if there is a problem |
ParseMultiLanguageString(String, String)
Returns the string part of the specified culture from the multi language string
These strings are typically used in SuperOffice list and description data
Declaration
public static string ParseMultiLanguageString(string multilangString, string cultureName)
Parameters
Type | Name | Description |
---|---|---|
System.String | multilangString | The multilanguage string to parse:
|
System.String | cultureName | The cultureName, typically en-US, nb-NO, but also US, NO is accepted |
Returns
Type | Description |
---|---|
System.String | Culture specific string part, or original string if there is a problem |
Remarks
This version will also accept strings that have non-multilanguage text before and after the multilanguage block, and even multiple multilanguage blocks (provided there is at least one non-conforming character between them), isolating them and parsing each one separately. Non-conforming text is kept in place in the output.
StripColon(String)
Strip a terminating colon from a string, and any whitespace
Declaration
public static string StripColon(string label)
Parameters
Type | Name | Description |
---|---|---|
System.String | label | String to process |
Returns
Type | Description |
---|---|
System.String | String, without colon and without leading/trailing whitespace |
StripCountrySpecificsFromLanguageName(String)
Converts "English (Zimbabwe)" into plain "English" by removing anything in parenthesis and stripping spaces.
Declaration
public static string StripCountrySpecificsFromLanguageName(string languageName)
Parameters
Type | Name | Description |
---|---|---|
System.String | languageName | Human readable language name: "Norsk (Bokmål)" or "Francaise" |
Returns
Type | Description |
---|---|
System.String | Simplified language name with initial capital: "Norsk" or "Francaise" |
StripTerminator(String, String)
Strip a terminator from a string. Whitespace is first trimmed from both sides of the string, the terminator is removed if present, and any whitespace now at the end of the string is also removed
Declaration
public static string StripTerminator(string label, string terminator)
Parameters
Type | Name | Description |
---|---|---|
System.String | label | String to process |
System.String | terminator | Terminator to remove |
Returns
Type | Description |
---|---|
System.String | Original string minus terminator |
TryParse(String, out DateTime)
Try to parse a string as an encoded or bare InvariantCulture DateTime
Declaration
public static bool TryParse(string encoded, out DateTime result)
Parameters
Type | Name | Description |
---|---|---|
System.String | encoded | String, either marked with [DT: ] or just a datetime |
System.DateTime | result | DateTime value, if return value is true; otherwise MinValue |
Returns
Type | Description |
---|---|
Boolean | true if parsing succeeded |
TryParse(String, out Double)
Try to parse a string as an encoded or bare InvariantCulture Double
Declaration
public static bool TryParse(string encoded, out double result)
Parameters
Type | Name | Description |
---|---|---|
System.String | encoded | String, either marked with [F: ] or just a date |
System.Double | result | Double value, if return value is true; otherwise 0 |
Returns
Type | Description |
---|---|
Boolean | true if parsing succeeded |
TryParse(String, out Int32)
Try to parse a string as an encoded or bare InvariantCulture Integer32
Declaration
public static bool TryParse(string encoded, out int result)
Parameters
Type | Name | Description |
---|---|---|
System.String | encoded | String, either marked with [I: ] or just an integer |
System.Int32 | result | Int value, if return value is true; otherwise 0 |
Returns
Type | Description |
---|---|
Boolean | true if parsing succeeded |
TryParse(String, out Int32[])
Declaration
public static bool TryParse(string encodedIntArr, out int[] result)
Parameters
Type | Name | Description |
---|---|---|
System.String | encodedIntArr | |
System.Int32[] | result |
Returns
Type | Description |
---|---|
Boolean |