OpenPetra
Free Administration Software for Non-Profits
Ict.Common.StringHelper Class Reference

General String utility functions for ICT applications. More...

Public Member Functions

String FormatUsingCurrencyCode (decimal AValue, String ACurrencyCode)
 Use this for displaying currency-sensitive amounts. More...
 
int DecimalPlacesForCurrency (String ACurrencyCode)
 

Static Public Member Functions

static StringCollection InitStrArr (string[] list)
 convert an array of strings into a StringCollection More...
 
static StringCollection StrSplit (string s, string delim)
 split a string using a delimiter and return a StringCollection containing the pieces of the string More...
 
static string StrMerge (StringCollection l, char delim)
 concatenate a string using the given delimiter More...
 
static string StrMerge (String[] l, char delim)
 concatenate a string using the given delimiter More...
 
static void JoinAndAppend (ref string AStringToExtend, string AStringToAppend, string AJoinString)
 Appends a string to another string. If the original length was non-zero the join string is inserted between the two strings. Often used to join SQL parts in a filter statement. More...
 
static StringCollection StrSort (StringCollection l)
 return a sorted version of the given StringCollection (not case sensitive) More...
 
static Boolean Contains (StringCollection haystack, StringCollection needles)
 check if a StringCollection haystack contains all of the needles More...
 
static Boolean ContainsSome (StringCollection haystack, StringCollection needles)
 check if a StringCollection haystack contains at least one of the needles More...
 
static Boolean IsSame (string s1, string s2)
 Tests if two strings are equal, case insensitive More...
 
static string CleanString (string s)
 removes line breaks and tabulators and trims spaces, even inside the string More...
 
static string TrimQuotes (string s)
 return the string without the quotes at the start and the end of the string More...
 
static string MD5Sum (string s)
 calcuate the md5 hash sum of a string More...
 
static string EncodeStringToBase64 (string APlainText)
 convert string to base64 More...
 
static int FindMatchingQuote (String s, int position)
 need to find the matching quotes More...
 
static int FindMatchingQuote (StringBuilder s, int position)
 need to find the matching quotes More...
 
static string GetCSVSeparator (string ACSVData)
 Get the separator from the first VALID line of CSV Data. Comments and blank lines are ignored. Leading spaces are ignored. The primary test is for tab, semicolon and comma. If the first item is a floating point number with a comma for a decimal separator it will need to be in quotes! All text within quotes is ignored. The character after the matching quote is also a candidate for being the separator. This character is returned if the separator is NOT tab, semicolon or comma. Thus quoted data separated by a space is correctly determined. More...
 
static string GetNextCSV (ref string line, List< String >ALines, ref int ALineCounter, string separator)
 parse csv values that spread across multiple lines More...
 
static string GetNextCSV (ref string list, string separator, Boolean ATryAllSeparators=false, Boolean ARemoveLeadingAndTrailingSpaces=false)
 retrieves the first value of the comma separated list, and removes the value from the list More...
 
static string GetNextCSV (ref StringBuilder list, char separator, Boolean ARemoveLeadingAndTrailingSpaces=false)
 retrieves the first value of the comma separated list, and removes the value from the list. This version of GetNextCSV is quite optimized, but less flexible than the other version. only supports single character separators, and works only with the specified separator More...
 
static string GetNextCSV (ref string list, string separator, string ADefaultValue)
 overload for GetNextCSV. if the value is empty, the default value will be used More...
 
static string GetNextCSV (ref string list, string[] separators)
 try to use different separators; first fitting separator is used More...
 
static string GetNextCSV (ref string list)
 overload for GetNextCSV this will use the comma as default separator More...
 
static String GetCSVValue (string list, int index)
 retrieves a specific value from a comma separated list, the list stays unchanged More...
 
static StringCollection GetCSVList (string list, string delimiter, bool trimmedValues=false)
 parse a line of CSV values, and return a StringCollection with the values More...
 
static Boolean ContainsCSV (string list, String AElement)
 checks if the list contains the given value More...
 
static string AddCSV (string line, string value, string separator=",")
 adds a new value to a comma separated list, adding a delimiter if necessary More...
 
static string ConcatCSV (string line1, string line2, string separator)
 concatenates two comma separated lists, adding a comma if necessary More...
 
static string ConcatCSV (string line1, string line2)
 concatenate two string using the comma as delimiter More...
 
static string GetNextToken (ref string AStringToParse)
 simple parser function a token is defined to be a group of characters separated by given separator characters eg. a word etc More...
 
static string DirName (string path)
 returns the directory portion of pathname, using the last / or \ character More...
 
static string BaseName (string path)
 returns the filename portion of pathname, using the last / or \ character More...
 
static string InitialCaps (string str)
 Capitalizes the first letter of a string. InitialCaps returns a string in which the first character is capitalized and all the remaining characters are lower-case. More...
 
static string UpperCamelCase (String AStr, bool AIgnorePrefix, bool AIgnorePostfix)
 return a string where all underscores are removed, and instead the character following the underscore has been converted to Uppercase, also the first character of the string More...
 
static string UpperCamelCase (String AStr, char ASeparator, bool AIgnorePrefix, bool AIgnorePostfix)
 General function for transforming a string from old style naming convention to new (e.g. a_account_hierarchy to AccountHierarchy) More...
 
static string UpperCamelCase (String AStr, bool AIgnorePrefix)
 overload of UpperCamelCase; will always use the postfix and not drop it More...
 
static string UpperCamelCase (String AStr)
 overload for UpperCamelCase; will not drop postfix or prefix More...
 
static string ReverseUpperCamelCase (String AStr)
 converts a string from UpperCamelCase back to a string with spaces; keeps the capital letters More...
 
static string AnsiQuotedStr (string s, string delim)
 A Quote character is inserted at the beginning and end of the string, and each Quote character in the string is doubled. More...
 
static string AnsiDeQuotedStr (string s, string delim)
 reverse function for AnsiQuotedStr this will remove the quotes and deal with quotes contained in the string More...
 
static decimal TryStrToDecimal (string s, decimal ADefault)
 this method attempts to convert a string to a decimal value; if it fails, no exception is thrown, but a default value is used instead More...
 
static Int64 TryStrToInt (string s, Int64 ADefault)
 attempt to parse a string for an Integer; if it fails, return a default value More...
 
static Int32 TryStrToInt32 (string s, Int32 ADefault)
 attempt to parse a string for an Integer; if it fails, return a default value More...
 
static decimal TryStrToCurr (string s)
 attempt to parse a string for an decimal this is a little special for currencies, which was more important in Delphi than it is now in C# More...
 
static string IntToStr (int i)
 print an integer into a string More...
 
static System.Int64 StrToInt (string s)
 parse a string and return the Integer value More...
 
static string DateToStr (System.DateTime date, string format)
 print a date into a string using a given format this will make sure that the correct separators are used (problem with dash and hyphen in original String.Format) More...
 
static String PartnerKeyToStr (System.Int64 APartnerKey)
 print a partner key with all leading zeros to a string a partner key has the form: 0027123456 More...
 
static System.Int64 StrToPartnerKey (String APartnerKeyString)
 parse a string and return the partner key More...
 
static String FormatStrToPartnerKeyString (String APartnerKeyString)
 format a partner key given as a string will add leading zeros etc will rotate the string, so drop a zero at the front in case there is an additional digit at the end this is used to help entering the partner key and always display leading zeros More...
 
static bool IsStringPositiveInteger (String APositiveInteger)
 checks if there is positive Integer in the string More...
 
static string BoolToStr (Boolean b)
 print a boolean value to string More...
 
static Boolean StrToBool (string s)
 reverse function for BoolToStr will parse a string for a boolean More...
 
static string NullToEmptyString (string s)
 makes sure that a null value is converted to an empty string, otherwise the string is returned. More...
 
static string NullOrEmptyStringToNull (string s)
 Returns a string if it isn't null or String.Empty, otherwise returns null. More...
 
static string TrimStringToNull (string s)
 Trims a string and returns null if the string is null or is all whitespace. More...
 
static String FormatCurrencyInternal (decimal d, String format)
 This method formats a currency value, using an MS Access Style format string. examples: "(#,##0.00)" "#,##0.00 CR" etc. It returns a string with the written value according to the format. This function is only used by FormatCurrency, which is the function that should be called from outside. More...
 
static String GetFormatString (String AVariantFormatString, String AGeneralFormatString)
 find the appropriate format string, using general format (for the whole column) and the type of the current value More...
 
static Boolean IsCurrencyFormatString (String AFormatString)
 check if the given format is for currencies More...
 
static String FormatCurrency (TVariant value, String format)
 print a currency value (actually all sorts of values, e.g. dates) into a string More...
 
static String FormatCurrency (decimal value, String format)
 overload for FormatCurrency, using a decimal value More...
 
static String GetLongMonthName (Int32 monthNr)
 returns the full name of the month, using .net localised information More...
 
static String DateToLocalizedString (DateTime ADateTime)
 return a string with just the date, no time information More...
 
static String DateToLocalizedString (DateTime ? ADateTime)
 overload for nullable DateTime More...
 
static String DateToLocalizedString (DateTime ADateTime, Boolean AIncludeTime)
 return a string with the date and optionally with the time More...
 
static String DateToLocalizedString (DateTime ADateTime, Boolean AIncludeTime, Boolean ATimeWithSeconds)
 Print a date to string, optionally with time and even seconds More...
 
static int FindMatchingEndBracket (string AInspectString, int AStartPos, char ABracketChar)
 Finds a matching closing bracket in a String. More...
 
static Boolean ContainsI (string s, string needle)
 check if the needle occurs in s, ignoring case sensitivity More...
 
static int CountOccurencesOfChar (string instance, char c)
 Count the occurences of a certain character in a string More...
 
static string[] SplitEmailAddresses (string AEmailAddress)
 Splits a string that contains one or more email addresses so that each email address becomes one item in a string array. More...
 
static string StrArrayToString (string[] AStringArrary, string ADelimiter="")
 Returns the elements of a string[] as one string, optionally adding a delimter between the elements if one is specified in Argument ADelimiter . More...
 
static string StrCollToString (StringCollection AStringColl, string ADelimiter="")
 Returns the elements of a StringCollection as one string, optionally adding a delimter between the elements if one is specified in Argument ADelimiter . More...
 
static CultureInfo GetCultureInfoForDateFormat (string ADateFormat)
 Get a CultureInfo object that is appropriate for the given Date Format. The most important consideration is when parsing short date formats. All other ones work fine in OpenPetra. When parsing short dates it is important to base the CultureInfo on a relevant base culture. We use en-US when the date format is month-first and en-GB otherwise (Day or Year first) More...
 
static bool LooksLikeFloat (string AString, out bool ? AIsDotDecimalSeparator)
 Evaluates a string and returns true if the text looks like a floating point number AND the decimal separator is unambiguous. If it does look like a float the method works out if the decimal separator looks like a dot or a comma. The method also considers whether dot or comma might be thousands separator. More...
 
static bool LooksLikeAmbiguousShortDate (string AString, bool ADateMayBeInteger, out DateTime AMonthFirstDate, out DateTime ADayFirstDate)
 Evaluates a string and returns true if the text looks like a date. If it appears to be a date the method returns two values - the date value if the text is parsed as month-first and the date value if the text is parsed as day-first. If either of them is an invalid date it will have DateTime.MinValue. Dates can have a separator of / - . or space. Note that .NET parses many date strings unambiguously even though the basic date format is quite simple. For the date formats that OpenPetra works with we really only need to distinguish between month-first short dates and day-first short dates. More...
 

Static Public Attributes

static readonly string CSV_STRING_FORMAT_ERROR = Catalog.GetString(">>STRING FORMAT ERROR<<")
 This string is returned by the CSV parser if it cannot successfully parse a text CSV field - usually due to mis-matched quote marks. More...
 
const String FINANCE_CURRENCY_FORMAT_AS_CURRENCY = "FinanceShowCurrencyAsCurrency"
 Show money amounts in currency format on finance screens (default is true) More...
 
const String FINANCE_DECIMAL_FORMAT_AS_CURRENCY = "FinanceShowDecimalAsCurrency"
 Show other decimal entities in currency format on finance screens (default is true) More...
 
const String FINANCE_CURRENCY_SHOW_THOUSANDS = "FinanceCurrencyShowThousands"
 Show thousands separator for financial entities on finance screens (default is true) More...
 
const String PARTNER_CURRENCY_FORMAT_AS_CURRENCY = "PartnerShowCurrencyAsCurrency"
 Show money amounts in currency format on partner/conference/personnel screens (default is false) More...
 
const String PARTNER_DECIMAL_FORMAT_AS_CURRENCY = "PartnerShowDecimalAsCurrency"
 Show other decimal entities in currency format on partner screens (default is false) More...
 
const String PARTNER_CURRENCY_SHOW_THOUSANDS = "PartnerCurrencyShowThousands"
 Show thousands separator for financial entities on partner/conference/personnel screens (default is true) More...
 

Properties

DataTable CurrencyFormatTable [set]
 If this is not given (during initialisation), a default format will be used. More...
 

Detailed Description

General String utility functions for ICT applications.

Member Function Documentation

◆ AddCSV()

static string Ict.Common.StringHelper.AddCSV ( string  line,
string  value,
string  separator = "," 
)
inlinestatic

adds a new value to a comma separated list, adding a delimiter if necessary

Parameters
linethe existing line, could be empty or hold already values
valuevalue to be added
separatordelimiter to use
Returns
the new list containing the old list and the new value

◆ AnsiDeQuotedStr()

static string Ict.Common.StringHelper.AnsiDeQuotedStr ( string  s,
string  delim 
)
inlinestatic

reverse function for AnsiQuotedStr this will remove the quotes and deal with quotes contained in the string

Parameters
sstring to be stripped of quotes
delimwhich quote character to look for and remove/replace
Returns
the string in non quoted form

◆ AnsiQuotedStr()

static string Ict.Common.StringHelper.AnsiQuotedStr ( string  s,
string  delim 
)
inlinestatic

A Quote character is inserted at the beginning and end of the string, and each Quote character in the string is doubled.

Parameters
sstring to be quoted
delimthe quote character to be used (could be single or double quote, etc)
Returns
the quoted string

◆ BaseName()

static string Ict.Common.StringHelper.BaseName ( string  path)
inlinestatic

returns the filename portion of pathname, using the last / or \ character

Parameters
paththe complete path
Returns
the filename portion of the path

◆ BoolToStr()

static string Ict.Common.StringHelper.BoolToStr ( Boolean  b)
inlinestatic

print a boolean value to string

Parameters
bboolean value
Returns
a string containing the boolean value

◆ CleanString()

static string Ict.Common.StringHelper.CleanString ( string  s)
inlinestatic

removes line breaks and tabulators and trims spaces, even inside the string

Parameters
sthe string that should be cleaned up
Returns
the clean string, without line breaks, tabulators and groups of spaces

◆ ConcatCSV() [1/2]

static string Ict.Common.StringHelper.ConcatCSV ( string  line1,
string  line2 
)
inlinestatic

concatenate two string using the comma as delimiter

Parameters
line1the first string
line2the second string
Returns
a list of the 2 strings

◆ ConcatCSV() [2/2]

static string Ict.Common.StringHelper.ConcatCSV ( string  line1,
string  line2,
string  separator 
)
inlinestatic

concatenates two comma separated lists, adding a comma if necessary

Parameters
line1first line, could be empty or hold already values
line2second line
separatordefaults to comma
Returns
the new list, consisting of the values of the 2 lists

◆ Contains()

static Boolean Ict.Common.StringHelper.Contains ( StringCollection  haystack,
StringCollection  needles 
)
inlinestatic

check if a StringCollection haystack contains all of the needles

Parameters
haystackthe StringCollection to be searched
needlesthe StringCollection containing the strings that are to be found
Returns
true if all strings can be found, false otherwise

◆ ContainsCSV()

static Boolean Ict.Common.StringHelper.ContainsCSV ( string  list,
String  AElement 
)
inlinestatic

checks if the list contains the given value

Parameters
listseparated values
AElementstring to look for in the list
Returns
true if the value is an element of the list

◆ ContainsI()

static Boolean Ict.Common.StringHelper.ContainsI ( string  s,
string  needle 
)
inlinestatic

check if the needle occurs in s, ignoring case sensitivity

◆ ContainsSome()

static Boolean Ict.Common.StringHelper.ContainsSome ( StringCollection  haystack,
StringCollection  needles 
)
inlinestatic

check if a StringCollection haystack contains at least one of the needles

Parameters
haystackthe StringCollection to be searched
needlesthe StringCollection containing the strings that are to be found
Returns
true if at least one string can be found, false if none can be found

◆ CountOccurencesOfChar()

static int Ict.Common.StringHelper.CountOccurencesOfChar ( string  instance,
char  c 
)
inlinestatic

Count the occurences of a certain character in a string

Parameters
instance
c
Returns

◆ DateToLocalizedString() [1/4]

static String Ict.Common.StringHelper.DateToLocalizedString ( DateTime ?  ADateTime)
inlinestatic

overload for nullable DateTime

Parameters
ADateTime
Returns

◆ DateToLocalizedString() [2/4]

static String Ict.Common.StringHelper.DateToLocalizedString ( DateTime  ADateTime)
inlinestatic

return a string with just the date, no time information

Parameters
ADateTimethe date to print
Returns
the date printed into a string

◆ DateToLocalizedString() [3/4]

static String Ict.Common.StringHelper.DateToLocalizedString ( DateTime  ADateTime,
Boolean  AIncludeTime 
)
inlinestatic

return a string with the date and optionally with the time

Parameters
ADateTimethe date to print
AIncludeTimeif true then the time is printed as well
Returns
the printed date

◆ DateToLocalizedString() [4/4]

static String Ict.Common.StringHelper.DateToLocalizedString ( DateTime  ADateTime,
Boolean  AIncludeTime,
Boolean  ATimeWithSeconds 
)
inlinestatic

Print a date to string, optionally with time and even seconds

Parameters
ADateTimethe date to print
AIncludeTimewant to print time
ATimeWithSecondswant to print seconds
Returns
the formatted date string

◆ DateToStr()

static string Ict.Common.StringHelper.DateToStr ( System.DateTime  date,
string  format 
)
inlinestatic

print a date into a string using a given format this will make sure that the correct separators are used (problem with dash and hyphen in original String.Format)

Parameters
datethe date to be printed
formatformat string, eg. dd/MM/yyyy; see help for String.Format
Returns

◆ DecimalPlacesForCurrency()

int Ict.Common.StringHelper.DecimalPlacesForCurrency ( String  ACurrencyCode)
inline

Parameters
ACurrencyCode
Returns

◆ DirName()

static string Ict.Common.StringHelper.DirName ( string  path)
inlinestatic

returns the directory portion of pathname, using the last / or \ character

Parameters
paththe complete path
Returns
the directory portion of the path

◆ EncodeStringToBase64()

static string Ict.Common.StringHelper.EncodeStringToBase64 ( string  APlainText)
inlinestatic

convert string to base64

◆ FindMatchingEndBracket()

static int Ict.Common.StringHelper.FindMatchingEndBracket ( string  AInspectString,
int  AStartPos,
char  ABracketChar 
)
inlinestatic

Finds a matching closing bracket in a String.

Parameters
AInspectStringThe String to inspect.
AStartPosStart position from which to search (must be >= 0).
ABracketCharOpening bracket character. Supported are '(', '[' and '{'.
Returns
If return value is positive: The position in string of the matching closing bracket. If return value is negative and not -9999: uneven opening and closing of bracktes. The number is the of missing closing brackets. If return value is -9999: AStartPos was greater than the string has characters!

◆ FindMatchingQuote() [1/2]

static int Ict.Common.StringHelper.FindMatchingQuote ( String  s,
int  position 
)
inlinestatic

need to find the matching quotes

Parameters
sString to the find the matching quote
positionposition of the first quote
Returns
index of the end matching quote in the string

◆ FindMatchingQuote() [2/2]

static int Ict.Common.StringHelper.FindMatchingQuote ( StringBuilder  s,
int  position 
)
inlinestatic

need to find the matching quotes

Parameters
sString to the find the matching quote
positionposition of the first quote
Returns
index of the end matching quote in the string

◆ FormatCurrency() [1/2]

static String Ict.Common.StringHelper.FormatCurrency ( decimal  value,
String  format 
)
inlinestatic

overload for FormatCurrency, using a decimal value

Parameters
valuevalue to be formatted
formatformat to be used
Returns
the formatted string

◆ FormatCurrency() [2/2]

static String Ict.Common.StringHelper.FormatCurrency ( TVariant  value,
String  format 
)
inlinestatic

print a currency value (actually all sorts of values, e.g. dates) into a string

Parameters
valuethe value to be printed
formatthe format to be used; can be dayofyear for birthdays, currency, etc
Returns
the formatted string

◆ FormatCurrencyInternal()

static String Ict.Common.StringHelper.FormatCurrencyInternal ( decimal  d,
String  format 
)
inlinestatic

This method formats a currency value, using an MS Access Style format string. examples: "(#,##0.00)" "#,##0.00 CR" etc. It returns a string with the written value according to the format. This function is only used by FormatCurrency, which is the function that should be called from outside.

Parameters
dthe double value to be formatted
formatformat to be used to print the double
Returns
the formatted currency string

◆ FormatStrToPartnerKeyString()

static String Ict.Common.StringHelper.FormatStrToPartnerKeyString ( String  APartnerKeyString)
inlinestatic

format a partner key given as a string will add leading zeros etc will rotate the string, so drop a zero at the front in case there is an additional digit at the end this is used to help entering the partner key and always display leading zeros

Parameters
APartnerKeyStringthe string to be formatted
Returns
the formatted string containing the partner key

◆ FormatUsingCurrencyCode()

String Ict.Common.StringHelper.FormatUsingCurrencyCode ( decimal  AValue,
String  ACurrencyCode 
)
inline

Use this for displaying currency-sensitive amounts.

Parameters
AValue
ACurrencyCode
Returns

◆ GetCSVList()

static StringCollection Ict.Common.StringHelper.GetCSVList ( string  list,
string  delimiter,
bool  trimmedValues = false 
)
inlinestatic

parse a line of CSV values, and return a StringCollection with the values

◆ GetCSVSeparator()

static string Ict.Common.StringHelper.GetCSVSeparator ( string  ACSVData)
inlinestatic

Get the separator from the first VALID line of CSV Data. Comments and blank lines are ignored. Leading spaces are ignored. The primary test is for tab, semicolon and comma. If the first item is a floating point number with a comma for a decimal separator it will need to be in quotes! All text within quotes is ignored. The character after the matching quote is also a candidate for being the separator. This character is returned if the separator is NOT tab, semicolon or comma. Thus quoted data separated by a space is correctly determined.

Parameters
ACSVDataMulti-line CSV data
Returns
null if the separator cannot be determined. Otherwise returns the separator.

◆ GetCSVValue()

static String Ict.Common.StringHelper.GetCSVValue ( string  list,
int  index 
)
inlinestatic

retrieves a specific value from a comma separated list, the list stays unchanged

Parameters
listthe comma separated list
indexindex of the value that should be returned, starting counts with 0
Returns
the value at the given position in the list

◆ GetCultureInfoForDateFormat()

static CultureInfo Ict.Common.StringHelper.GetCultureInfoForDateFormat ( string  ADateFormat)
inlinestatic

Get a CultureInfo object that is appropriate for the given Date Format. The most important consideration is when parsing short date formats. All other ones work fine in OpenPetra. When parsing short dates it is important to base the CultureInfo on a relevant base culture. We use en-US when the date format is month-first and en-GB otherwise (Day or Year first)

◆ GetFormatString()

static String Ict.Common.StringHelper.GetFormatString ( String  AVariantFormatString,
String  AGeneralFormatString 
)
inlinestatic

find the appropriate format string, using general format (for the whole column) and the type of the current value

Parameters
AVariantFormatStringwhat kind of value are we talking about, eg. currency
AGeneralFormatStringdefining the format on a higher level, e.g. CurrencyWithoutDecimals or CurrencyThousands etc
Returns
a string format similar to Access string format (format for positive, negative, zero, null)

◆ GetLongMonthName()

static String Ict.Common.StringHelper.GetLongMonthName ( Int32  monthNr)
inlinestatic

returns the full name of the month, using .net localised information

Parameters
monthNrthe number of the month (starting January = 1)
Returns
the printed name of the month

◆ GetNextCSV() [1/6]

static string Ict.Common.StringHelper.GetNextCSV ( ref string  line,
List< String >  ALines,
ref int  ALineCounter,
string  separator 
)
inlinestatic

parse csv values that spread across multiple lines

Parameters
line
ALines
ALineCounter
separator
Returns

◆ GetNextCSV() [2/6]

static string Ict.Common.StringHelper.GetNextCSV ( ref string  list)
inlinestatic

overload for GetNextCSV this will use the comma as default separator

Parameters
listseparated values; the first value will be removed
Returns
the first value of the string

◆ GetNextCSV() [3/6]

static string Ict.Common.StringHelper.GetNextCSV ( ref string  list,
string  separator,
Boolean  ATryAllSeparators = false,
Boolean  ARemoveLeadingAndTrailingSpaces = false 
)
inlinestatic

retrieves the first value of the comma separated list, and removes the value from the list

Parameters
listthe comma separated list that will get the first value removed
separatorthe delimiter/separator of the list
ATryAllSeparatorsif this is true, a number of default separators (slash, comma, etc) will be used
ARemoveLeadingAndTrailingSpacesif this is true, leading and trailing spaces will be discarded (useful for file imports)
Returns
the first value of the list

◆ GetNextCSV() [4/6]

static string Ict.Common.StringHelper.GetNextCSV ( ref string  list,
string  separator,
string  ADefaultValue 
)
inlinestatic

overload for GetNextCSV. if the value is empty, the default value will be used

Parameters
listseparated values; the first value will be removed
separatordelimiter to be used
ADefaultValueto be used if the csv value is empty
Returns
the first value of the string

◆ GetNextCSV() [5/6]

static string Ict.Common.StringHelper.GetNextCSV ( ref string  list,
string[]  separators 
)
inlinestatic

try to use different separators; first fitting separator is used

Parameters
list
separators
Returns

◆ GetNextCSV() [6/6]

static string Ict.Common.StringHelper.GetNextCSV ( ref StringBuilder  list,
char  separator,
Boolean  ARemoveLeadingAndTrailingSpaces = false 
)
inlinestatic

retrieves the first value of the comma separated list, and removes the value from the list. This version of GetNextCSV is quite optimized, but less flexible than the other version. only supports single character separators, and works only with the specified separator

Parameters
listthe comma separated list that will get the first value removed
separatorthe delimiter/separator of the list
ARemoveLeadingAndTrailingSpacesif this is true, leading and trailing spaces will be discarded (useful for file imports)
Returns
the first value of the list

◆ GetNextToken()

static string Ict.Common.StringHelper.GetNextToken ( ref string  AStringToParse)
inlinestatic

simple parser function a token is defined to be a group of characters separated by given separator characters eg. a word etc

Parameters
AStringToParsethe string to be parsed; the first token will be removed
Returns
the first token; skips the separators (eg. spaces)

◆ InitialCaps()

static string Ict.Common.StringHelper.InitialCaps ( string  str)
inlinestatic

Capitalizes the first letter of a string. InitialCaps returns a string in which the first character is capitalized and all the remaining characters are lower-case.

Parameters
strString to be converted.
Returns
String formatted with an initial capital.

◆ InitStrArr()

static StringCollection Ict.Common.StringHelper.InitStrArr ( string[]  list)
inlinestatic

convert an array of strings into a StringCollection

Parameters
listarray of strings
Returns
a new StringCollection containing the strings

◆ IntToStr()

static string Ict.Common.StringHelper.IntToStr ( int  i)
inlinestatic

print an integer into a string

Parameters
ithe integer value
Returns
a string containing the integer value

◆ IsCurrencyFormatString()

static Boolean Ict.Common.StringHelper.IsCurrencyFormatString ( String  AFormatString)
inlinestatic

check if the given format is for currencies

Parameters
AFormatStringformat string to check
Returns
true if the format contains the name currency or characters that are indicating a currency format

◆ IsSame()

static Boolean Ict.Common.StringHelper.IsSame ( string  s1,
string  s2 
)
inlinestatic

Tests if two strings are equal, case insensitive

Parameters
s1the first string to be compared
s2the other string to be compared
Returns
true if the strings are equal, not considering case sensitivity

◆ IsStringPositiveInteger()

static bool Ict.Common.StringHelper.IsStringPositiveInteger ( String  APositiveInteger)
inlinestatic

checks if there is positive Integer in the string

Parameters
APositiveIntegerstring to check
Returns
true if greater or equals 0

◆ JoinAndAppend()

static void Ict.Common.StringHelper.JoinAndAppend ( ref string  AStringToExtend,
string  AStringToAppend,
string  AJoinString 
)
inlinestatic

Appends a string to another string. If the original length was non-zero the join string is inserted between the two strings. Often used to join SQL parts in a filter statement.

Parameters
AStringToExtendThe string to extend. May be empty
AStringToAppendThe string to append
AJoinStringA string that joins the other two. If the first string is empty the join is not used. There are some predefined strings in the CommonJoinStrings class.

◆ LooksLikeAmbiguousShortDate()

static bool Ict.Common.StringHelper.LooksLikeAmbiguousShortDate ( string  AString,
bool  ADateMayBeInteger,
out DateTime  AMonthFirstDate,
out DateTime  ADayFirstDate 
)
inlinestatic

Evaluates a string and returns true if the text looks like a date. If it appears to be a date the method returns two values - the date value if the text is parsed as month-first and the date value if the text is parsed as day-first. If either of them is an invalid date it will have DateTime.MinValue. Dates can have a separator of / - . or space. Note that .NET parses many date strings unambiguously even though the basic date format is quite simple. For the date formats that OpenPetra works with we really only need to distinguish between month-first short dates and day-first short dates.

Parameters
AStringThe string to evaluate
ADateMayBeIntegerSet to true if the option to include numeric dates such as 311216 should be included
AMonthFirstDateIf successful this will be the date if the month is first, otherwise DateTime.MinValue
ADayFirstDateIf successful this will be the date if the day is first, otherwise DateTime.MinValue
Returns

◆ LooksLikeFloat()

static bool Ict.Common.StringHelper.LooksLikeFloat ( string  AString,
out bool ?  AIsDotDecimalSeparator 
)
inlinestatic

Evaluates a string and returns true if the text looks like a floating point number AND the decimal separator is unambiguous. If it does look like a float the method works out if the decimal separator looks like a dot or a comma. The method also considers whether dot or comma might be thousands separator.

Parameters
AString
AIsDotDecimalSeparator
Returns
Return false if the decimal separator is neither dot nor comma OR if it could be either

◆ MD5Sum()

static string Ict.Common.StringHelper.MD5Sum ( string  s)
inlinestatic

calcuate the md5 hash sum of a string

Parameters
s
Returns

◆ NullOrEmptyStringToNull()

static string Ict.Common.StringHelper.NullOrEmptyStringToNull ( string  s)
inlinestatic

Returns a string if it isn't null or String.Empty, otherwise returns null.

Parameters
sString.
Returns
Null if the string is null or is String.Empty, otherwise the string.

◆ NullToEmptyString()

static string Ict.Common.StringHelper.NullToEmptyString ( string  s)
inlinestatic

makes sure that a null value is converted to an empty string, otherwise the string is returned.

Parameters
sthe string which can be null or have a proper string value
Returns
empty string or the contents of s

◆ PartnerKeyToStr()

static String Ict.Common.StringHelper.PartnerKeyToStr ( System.Int64  APartnerKey)
inlinestatic

print a partner key with all leading zeros to a string a partner key has the form: 0027123456

Parameters
APartnerKeypartner key to be printed
Returns
the string containing a formatted version of the partner key

◆ ReverseUpperCamelCase()

static string Ict.Common.StringHelper.ReverseUpperCamelCase ( String  AStr)
inlinestatic

converts a string from UpperCamelCase back to a string with spaces; keeps the capital letters

◆ SplitEmailAddresses()

static string[] Ict.Common.StringHelper.SplitEmailAddresses ( string  AEmailAddress)
inlinestatic

Splits a string that contains one or more email addresses so that each email address becomes one item in a string array.

◆ StrArrayToString()

static string Ict.Common.StringHelper.StrArrayToString ( string[]  AStringArrary,
string  ADelimiter = "" 
)
inlinestatic

Returns the elements of a string[] as one string, optionally adding a delimter between the elements if one is specified in Argument ADelimiter .

Parameters
AStringArraryString array.
ADelimiterDelimiter (optional).
Returns
String array elements concatenated into a string.

◆ StrCollToString()

static string Ict.Common.StringHelper.StrCollToString ( StringCollection  AStringColl,
string  ADelimiter = "" 
)
inlinestatic

Returns the elements of a StringCollection as one string, optionally adding a delimter between the elements if one is specified in Argument ADelimiter .

Parameters
AStringCollStringCollection.
ADelimiterDelimiter (optional).
Returns
StringCollection elements concatenated into string.

◆ StrMerge() [1/2]

static string Ict.Common.StringHelper.StrMerge ( String[]  l,
char  delim 
)
inlinestatic

concatenate a string using the given delimiter

Parameters
lthe string array containing the strings that should be concatenated
delimthe delimiter to be used between the strings
Returns
a string with the concatenated strings from the string array

◆ StrMerge() [2/2]

static string Ict.Common.StringHelper.StrMerge ( StringCollection  l,
char  delim 
)
inlinestatic

concatenate a string using the given delimiter

Parameters
lthe StringCollection containing the strings that should be concatenated
delimthe delimiter to be used between the strings
Returns
a string with the concatenated strings from the StringCollection

◆ StrSort()

static StringCollection Ict.Common.StringHelper.StrSort ( StringCollection  l)
inlinestatic

return a sorted version of the given StringCollection (not case sensitive)

Parameters
lthe StringCollection to be used to generate a sorted list
Returns
the sorted StringCollection

◆ StrSplit()

static StringCollection Ict.Common.StringHelper.StrSplit ( string  s,
string  delim 
)
inlinestatic

split a string using a delimiter and return a StringCollection containing the pieces of the string

Parameters
sthe string to split
delimthe delimiter to use
Returns
a StringCollection with the pieces of the string

◆ StrToBool()

static Boolean Ict.Common.StringHelper.StrToBool ( string  s)
inlinestatic

reverse function for BoolToStr will parse a string for a boolean

Parameters
sstring containing the bool value
Returns
boolean value

◆ StrToInt()

static System.Int64 Ict.Common.StringHelper.StrToInt ( string  s)
inlinestatic

parse a string and return the Integer value

Parameters
sthe string containing the integer value
Returns
the integer value

◆ StrToPartnerKey()

static System.Int64 Ict.Common.StringHelper.StrToPartnerKey ( String  APartnerKeyString)
inlinestatic

parse a string and return the partner key

Parameters
APartnerKeyStringstring containing the partner key
Returns
the Integer value of the partner key

◆ TrimQuotes()

static string Ict.Common.StringHelper.TrimQuotes ( string  s)
inlinestatic

return the string without the quotes at the start and the end of the string

Parameters
s
Returns

◆ TrimStringToNull()

static string Ict.Common.StringHelper.TrimStringToNull ( string  s)
inlinestatic

Trims a string and returns null if the string is null or is all whitespace.

Parameters
sString.
Returns
Null if the string is null or is all whitespace, otherwise the trimmed string.

◆ TryStrToCurr()

static decimal Ict.Common.StringHelper.TryStrToCurr ( string  s)
inlinestatic

attempt to parse a string for an decimal this is a little special for currencies, which was more important in Delphi than it is now in C#

Parameters
sthe string containing a currency value
Returns
the decimal value

◆ TryStrToDecimal()

static decimal Ict.Common.StringHelper.TryStrToDecimal ( string  s,
decimal  ADefault 
)
inlinestatic

this method attempts to convert a string to a decimal value; if it fails, no exception is thrown, but a default value is used instead

Parameters
sstring that should contain a float
ADefaultvalue to be used if there is no float in the string
Returns
the decimal value or the default value

◆ TryStrToInt()

static Int64 Ict.Common.StringHelper.TryStrToInt ( string  s,
Int64  ADefault 
)
inlinestatic

attempt to parse a string for an Integer; if it fails, return a default value

Parameters
sthe string containing an Integer
ADefaultalternative default value
Returns
the Integer value or the default value

◆ TryStrToInt32()

static Int32 Ict.Common.StringHelper.TryStrToInt32 ( string  s,
Int32  ADefault 
)
inlinestatic

attempt to parse a string for an Integer; if it fails, return a default value

Parameters
sthe string containing an Integer
ADefaultalternative default value
Returns
the Integer value or the default value

◆ UpperCamelCase() [1/4]

static string Ict.Common.StringHelper.UpperCamelCase ( String  AStr)
inlinestatic

overload for UpperCamelCase; will not drop postfix or prefix

Parameters
AStrstring to be changed
Returns
converted string

◆ UpperCamelCase() [2/4]

static string Ict.Common.StringHelper.UpperCamelCase ( String  AStr,
bool  AIgnorePrefix 
)
inlinestatic

overload of UpperCamelCase; will always use the postfix and not drop it

Parameters
AStrstring to be modified
AIgnorePrefixshould prefix be ignored
Returns
converted string

◆ UpperCamelCase() [3/4]

static string Ict.Common.StringHelper.UpperCamelCase ( String  AStr,
bool  AIgnorePrefix,
bool  AIgnorePostfix 
)
inlinestatic

return a string where all underscores are removed, and instead the character following the underscore has been converted to Uppercase, also the first character of the string

Parameters
AStrthe string to be transformed
AIgnorePrefixstrip any prefix
AIgnorePostfixstrip any postfix
Returns
the string in new convention

◆ UpperCamelCase() [4/4]

static string Ict.Common.StringHelper.UpperCamelCase ( String  AStr,
char  ASeparator,
bool  AIgnorePrefix,
bool  AIgnorePostfix 
)
inlinestatic

General function for transforming a string from old style naming convention to new (e.g. a_account_hierarchy to AccountHierarchy)

Parameters
AStrstring to be transformed
ASeparatorseparator that will mark the next character for uppercase
AIgnorePrefixshould prefixes be ignored
AIgnorePostfixshould postfixes be ignored
Returns
the string in new convention

Member Data Documentation

◆ CSV_STRING_FORMAT_ERROR

readonly string Ict.Common.StringHelper.CSV_STRING_FORMAT_ERROR = Catalog.GetString(">>STRING FORMAT ERROR<<")
static

This string is returned by the CSV parser if it cannot successfully parse a text CSV field - usually due to mis-matched quote marks.

◆ FINANCE_CURRENCY_FORMAT_AS_CURRENCY

const String Ict.Common.StringHelper.FINANCE_CURRENCY_FORMAT_AS_CURRENCY = "FinanceShowCurrencyAsCurrency"
static

Show money amounts in currency format on finance screens (default is true)

◆ FINANCE_CURRENCY_SHOW_THOUSANDS

const String Ict.Common.StringHelper.FINANCE_CURRENCY_SHOW_THOUSANDS = "FinanceCurrencyShowThousands"
static

Show thousands separator for financial entities on finance screens (default is true)

◆ FINANCE_DECIMAL_FORMAT_AS_CURRENCY

const String Ict.Common.StringHelper.FINANCE_DECIMAL_FORMAT_AS_CURRENCY = "FinanceShowDecimalAsCurrency"
static

Show other decimal entities in currency format on finance screens (default is true)

◆ PARTNER_CURRENCY_FORMAT_AS_CURRENCY

const String Ict.Common.StringHelper.PARTNER_CURRENCY_FORMAT_AS_CURRENCY = "PartnerShowCurrencyAsCurrency"
static

Show money amounts in currency format on partner/conference/personnel screens (default is false)

◆ PARTNER_CURRENCY_SHOW_THOUSANDS

const String Ict.Common.StringHelper.PARTNER_CURRENCY_SHOW_THOUSANDS = "PartnerCurrencyShowThousands"
static

Show thousands separator for financial entities on partner/conference/personnel screens (default is true)

◆ PARTNER_DECIMAL_FORMAT_AS_CURRENCY

const String Ict.Common.StringHelper.PARTNER_DECIMAL_FORMAT_AS_CURRENCY = "PartnerShowDecimalAsCurrency"
static

Show other decimal entities in currency format on partner screens (default is false)

Property Documentation

◆ CurrencyFormatTable

DataTable Ict.Common.StringHelper.CurrencyFormatTable
set

If this is not given (during initialisation), a default format will be used.


The documentation for this class was generated from the following file: