Class StringTricks
This is a class of static methods (functions) for performing common tasks not provided by the System.String class. Most, but not all, have become obsolete, and are being retired in favor of the StringExtensions class in the WizardWrx.Core namespace.
Inheritance
Inherited Members
Namespace: WizardWrx
Assembly: WizardWrx.Common.dll
Syntax
public static class StringTricks
Fields
| Improve this Doc View SourceDEFAULT_TOKEN_DELM
Default token terminator string used by the version of public static method, MakeToken, which takes one argument.
Declaration
public const string DEFAULT_TOKEN_DELM = "$$"
Field Value
Type | Description |
---|---|
System.String |
MAXIMUM_CHARACTERS_TO_DISPLAY
Take this as the default value of the second argument to TruncateValueToOneLine.
Declaration
public const int MAXIMUM_CHARACTERS_TO_DISPLAY = 132
Field Value
Type | Description |
---|---|
System.Int32 |
Methods
| Improve this Doc View SourceAdjustNumberOfNoun(UInt32, String, String, String)
If the count of objects to which a noun refers is greater than 1, replace its singular form with its plural form. Use this method to generate grammatically correct sentences in which the noun's number is grammatically correct.
Declaration
public static string AdjustNumberOfNoun(uint puintNumber, string pstrNounSingular, string pstrPluralForm, string pstrPhrase)
Parameters
Type | Name | Description |
---|---|---|
System.UInt32 | puintNumber | Base the adjustment on this number. |
System.String | pstrNounSingular | Specify the noun to adjust, which is assumed to be in its singular form, and that its plural is the same word with the letter "S" appended. |
System.String | pstrPluralForm | Specify the plural form of pstrSingularForm, either outright or as a plus sign followed immediately by the suffix to append. If this arguments is a null reference or the empty string, the hard coded default suffix, a lower case s, is appended. |
System.String | pstrPhrase | Replace all instances of pstrNoun in this string with the plural of pstrNoun if pintNumber is greater than 1. |
Returns
Type | Description |
---|---|
System.String | The return value is pstrPhrase, amended if needed to reflect the correct number for pstrNoun. |
AppendFullStopIfMissing(String)
Unless the last character of the input string is a period (full stop), append one to the returned string.
Declaration
[Obsolete("Use the corresponding extension method.", false)]
public static string AppendFullStopIfMissing(string pstrInput)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrInput | Specify the input string to evaluate and edit as needed. |
Returns
Type | Description |
---|---|
System.String | The input string is returned with a period appended to it. If it already has one, the input string is returned without changes. |
ArrayOfOne(Char)
Return a one-element array containing the input character, for use as input to the Split method of the system.string class.
Declaration
[Obsolete("Use the corresponding extension method.", false)]
public static char[] ArrayOfOne(char pchrTheCharacter)
Parameters
Type | Name | Description |
---|---|---|
System.Char | pchrTheCharacter | Character to use as the split delimiter. |
Returns
Type | Description |
---|---|
System.Char[] | Array of one element, ready to feed to the string.split method. |
ArrayOfOne(String)
Return a one-element array containing the input string, for use as input to the Split method of the system.string class.
Declaration
[Obsolete("Use the corresponding extension method.", false)]
public static string[] ArrayOfOne(string pstrTheString)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrTheString | String to use as the split delimiter. |
Returns
Type | Description |
---|---|
System.String[] | Array of one element, ready to feed to the string.split method. |
Chop(String)
Return a new string with the terminal newline, if present, removed.
Declaration
[Obsolete("Use the corresponding extension method.", false)]
public static string Chop(string pstrIn)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrIn | String to be chopped |
Returns
Type | Description |
---|---|
System.String | Chopped string |
CountSubstrings(String, String)
Strangely, the String class is missing an important static method to count substrings within a string. This is the missing method.
Declaration
[Obsolete("Use the corresponding extension method.", false)]
public static int CountSubstrings(string pstrSource, string pstrToCount)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrSource | String in which to count occurrences of substring pstrToCount. If pstrSource is null or empty, the method returns zero. |
System.String | pstrToCount | Substring to count in string pstrSource. An empty string causes the method to return MagicNumbers.STRING_INDEXOF_NOT_FOUND, or -1. |
Returns
Type | Description |
---|---|
System.Int32 | Number of times, if any, that string pstrToCount occurs in string pstrSource, or MagicNumbers.STRING_INDEXOF_NOT_FOUND (-1) if pstrToCount is either null or empty. |
CountSubstrings(String, String, StringComparison)
Strangely, the String class is missing an important static method to count substrings within a string. This is the missing method.
Declaration
[Obsolete("Use the corresponding extension method.", false)]
public static int CountSubstrings(string pstrSource, string pstrToCount, StringComparison penmComparisonType)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrSource | String in which to count occurrences of substring pstrToCount. If pstrSource is null or empty, the method returns zero. |
System.String | pstrToCount | Substring to count in string pstrSource. An empty string causes the method to return MagicNumbers.STRING_INDEXOF_NOT_FOUND, or -1. |
System.StringComparison | penmComparisonType | A member of the StringComparison enumeration, which defines the rules for performing the comparison. |
Returns
Type | Description |
---|---|
System.Int32 | Number of times, if any, that string pstrToCount occurs in string pstrSource, or MagicNumbers.STRING_INDEXOF_NOT_FOUND (-1) if pstrToCount is either null or empty. |
DisplayNullSafely(Object)
Wrap an object reference that may happen to be null in a call to this method to guarantee that passing it into a method such as string.Format, Console.WriteLine, or one of their many cousins, to prevent it throwing a null reference exception.
Declaration
public static string DisplayNullSafely(object pobjAnything)
Parameters
Type | Name | Description |
---|---|---|
System.Object | pobjAnything | Since everything inherits a Tostring method from Object, this method is safe for all types. |
Returns
Type | Description |
---|---|
System.String | The return value is either the string representation of the input or a string representation of the word "null" enclosed in square brackets. |
EncloseInChar(String, Char)
Append a specified character to both ends of a string, unless it is already present.
Declaration
[Obsolete("Use the corresponding extension method.", false)]
public static string EncloseInChar(string pstrIn, char pchrEnd)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrIn | String to evaluate, which may, or may not, end with the character specified in pchrEnd. |
System.Char | pchrEnd | Character to append, if absent. |
Returns
Type | Description |
---|---|
System.String | String with character pchrEnd at both ends. |
ExtractBetweenIndexOfs(String, Int32, Int32)
Extract the substring bounded by the characters at either end of it.
Declaration
[Obsolete("Use the corresponding extension method.", false)]
public static string ExtractBetweenIndexOfs(string pstrWholeString, int pintPosBegin, int pintPosEnd)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrWholeString | Extract the substring from this string. |
System.Int32 | pintPosBegin | This integer is the position, given by IndexOf, of the character that bounds the left end of the desired substring. |
System.Int32 | pintPosEnd | This integer is the position, given by IndexOf, of the character that bounds the right end of the desired substring. |
Returns
Type | Description |
---|---|
System.String | The returned substring begins with the character immediately to the right of the left hand bounding character, and ending with the last character before the right hand bounding character. |
ExtractBetweenIndexOfs(String, String, Int32, Int32)
Extract the substring bounded by the characters at either end of it.
Declaration
[Obsolete("Use the corresponding extension method.", false)]
public static string ExtractBetweenIndexOfs(string pstrWholeString, string pstrLeftMarker, int pintPosBegin, int pintPosEnd)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrWholeString | Extract the substring from this string. |
System.String | pstrLeftMarker | This overload handles the case where the left boundary is bounded by a string. The method needs a copy of the string in order to find the true beginning of the substring to extract, and to compute its length. |
System.Int32 | pintPosBegin | This integer is the position, given by IndexOf, of the character that bounds the left end of the desired substring. |
System.Int32 | pintPosEnd | This integer is the position, given by IndexOf, of the character that bounds the right end of the desired substring. |
Returns
Type | Description |
---|---|
System.String | The returned substring begins with the character immediately to the right of the left hand bounding character, and ending with the last character before the right hand bounding character. Inputs and computed values are thoroughly sanity checked to prevent run-time exceptions. If anything is out of order, an empty string is returned. |
ExtractBoundedSubstrings(String, Char)
Extract a substring that is bounded by a character. See Remarks.
Declaration
[Obsolete("Use the corresponding extension method.", false)]
public static string ExtractBoundedSubstrings(string pstrWholeString, char pchrBoundingCharacter)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrWholeString | The substring is extracted from this string. |
System.Char | pchrBoundingCharacter | This is the bounding character. Please see Remarks. |
Returns
Type | Description |
---|---|
System.String | This is the desired substring, without its bounding characters. See Remarks. |
Remarks
The left and right ends must be bounded by the same character. To extract a string bounded on each end by a different character, use the next overload.
Inputs and computed values are thoroughly sanity checked to prevent run-time exceptions. If anything is out of order, an empty string is returned.
ExtractBoundedSubstrings(String, Char, Char)
Extract a substring that is bounded by a character. See Remarks.
Declaration
[Obsolete("Use the corresponding extension method.", false)]
public static string ExtractBoundedSubstrings(string pstrWholeString, char pchrLeftBound, char pchrRightBound)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrWholeString | The substring is extracted from this string. |
System.Char | pchrLeftBound | This is the character that marks the left end of the string. See Remarks. |
System.Char | pchrRightBound | This is the character that marks the right end of the string. See Remarks. |
Returns
Type | Description |
---|---|
System.String | This is the desired substring, without its bounding characters. See Remarks. |
Remarks
The left and right ends are expected to be bounded by different characters. To extract a string bounded on each end by the same character, use the previous overload.
Inputs and computed values are thoroughly sanity checked to prevent run-time exceptions. If anything is out of order, an empty string is returned.
ExtractBoundedSubstrings(String, String, String)
Extract a substring that is bounded by a pair of substrings. See Remarks.
Declaration
[Obsolete("Use the corresponding extension method.", false)]
public static string ExtractBoundedSubstrings(string pstrWholeString, string pstrLeftBound, string pstrRightBound)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrWholeString | The substring is extracted from this string. |
System.String | pstrLeftBound | This is the substring that marks the left end of the string. See Remarks. |
System.String | pstrRightBound | This is the substring that marks the right end of the string. See Remarks. |
Returns
Type | Description |
---|---|
System.String | This is the desired substring, without its bounding substrings. See Remarks. |
Remarks
The left and right ends are expected to be bounded by different substrings. To extract a string bounded on each end by the same substring, use the same value for the third and fourth arguments.
Inputs and computed values are thoroughly sanity checked to prevent run-time exceptions. If anything is out of order, an empty string is returned.
LengthOfLongestString(String[])
Given an array of strings, return the length of the longest string.
Declaration
public static int LengthOfLongestString(string[] pastrTheseStrings)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | pastrTheseStrings | The list of strings to evaluate is supplied as an array of strings, which may be an anonymous array, constructed on the fly in the argument list. |
Returns
Type | Description |
---|---|
System.Int32 | The return value is the length of the longest string. If the array is empty or is composed entirely of empty strings, the return value is zero. Since it begins with a null reference test, this routine is always successful. |
Remarks
Feed the return value to the PadRight method on a string to get back a string that, when used as a label, yields vertically aligned data.
MakeToken(String)
Given a string containing the name of a form control (field) or other token, create its place holder token.
Declaration
[Obsolete("Use the corresponding extension method.", false)]
public static string MakeToken(string pstrFieldName)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrFieldName | String containing the name of the token. |
Returns
Type | Description |
---|---|
System.String | String containing the text of the corresponding template text place holder. See Remarks. |
Remarks
The string is constructed by appending a standard token delimiter, which is a pair of dollar signs, to each end of the string.
The token is exposed as a static property, DEFAULT_TOKEN_DELM.
MakeToken(String, String)
Given a string containing the name of a form control (field) or other token, and another string containing a static token, create its place holder token.
Declaration
[Obsolete("Use the corresponding extension method.", false)]
public static string MakeToken(string pstrFieldName, string pstrTokenEnds)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrFieldName | String containing the name of the token. |
System.String | pstrTokenEnds |
Returns
Type | Description |
---|---|
System.String | The string is constructed by appending the token delimiter specified in argument pstrTokenEnds to both ends of the string specified in argument pstrFieldName. |
ParseCommentInHTMLComment(String)
Extract parameters, expressed as key-value pairs, from a standard HTML comment.
Declaration
[Obsolete("Use the corresponding extension method.", false)]
public static NameValueCollection ParseCommentInHTMLComment(string pstrInput)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrInput | String containing a well formed HTML comment, surrounding the key-value pairs. If the string is not a well formed HTML comment, with a single space between the comment delimiters and the body, or the string is null or empty, the returned collection is empty. |
Returns
Type | Description |
---|---|
System.Collections.Specialized.NameValueCollection | A NameValueCollection of parameter names and values, which may be empty, but is guaranteed to be returned, empty or not. |
Examples
Parse this: <!-- ForPage=default;UseTable=False -->
Return this:
=======================
Name Value
----------- -----------
ForPage default
UseTable False
=======================
The returned NameValueCollection contains two members.
Since this method guarantees to return an initialized NameValueCollection, the empty collection is allocated by the first statement, and is unconditionally returned by the last statement.
| Improve this Doc View SourceQuoteString(String)
Append a quote character to both ends of a string, unless it is already present.
Declaration
[Obsolete("Use the corresponding extension method.", false)]
public static string QuoteString(string pstrIn)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrIn | String to evaluate, which may, or may not, end with the characterr specified in pchrEnd. |
Returns
Type | Description |
---|---|
System.String | String with quote character at both ends. |
RemoveEndChars(String, Char)
Remove ending character, such as brackets, from a string, if present.
Declaration
[Obsolete("Use the corresponding extension method.", false)]
public static string RemoveEndChars(string pstrIn, char pchrEnd)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrIn | String to evaluate, which may, or may not, end with the characterr specified in pchrEnd. |
System.Char | pchrEnd | Character to remove, if present. |
Returns
Type | Description |
---|---|
System.String | String with character pchrEnd removed from both ends. |
RemoveEndQuotes(String)
Remove ending quotation marks from a string, if present.
Declaration
[Obsolete("Use the corresponding extension method.", false)]
public static string RemoveEndQuotes(string pstrIn)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrIn | String to evaluate, which may, or may not, end with quotes. |
Returns
Type | Description |
---|---|
System.String | String with ending quotes, if present, removed. |
ReplaceToken(String, String, String)
Given a string of text, another string of place holder text, which occurs zero or more times in the input string, return a string in which the place holder text is replaced with new text, supplied by the third argument.
Declaration
[Obsolete("Use the corresponding extension method.", false)]
public static string ReplaceToken(string pstrToSearch, string pstrToFind, string strReplaceWith)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrToSearch | String to be searched and changed. |
System.String | pstrToFind | String to be found and replaced. |
System.String | strReplaceWith | String to substitute for all occurrences of string pstrToFind. |
Returns
Type | Description |
---|---|
System.String | String pstrToSearch, with all occurrences of string pstrToFind replaced with string strReplaceWith. |
Remarks
Say it's syntactic sugar if you insist, but I'll keep using it in my code, and may eventually implement a version that takes references as arguments.
ReplaceTokensFromList(String, Dictionary<String, Object>)
Given a string containing tokens of the form "^^ListKeyValue^^" where ListKeyValue is the value of a key in the pnvcList collection, which may or may not exist in the collection, replace all such tokens with the contents of the like named value in the collection.
Declaration
[Obsolete("Use the corresponding extension method.", false)]
public static string ReplaceTokensFromList(string pstrMsg, Dictionary<string, object> pdctList)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrMsg | String containing the message containing the substitution tokens. |
System.Collections.Generic.Dictionary<System.String, System.Object> | pdctList | A Dictionary, in which each key represents a token, and its value represents the value to be substituted for it. The Dictionary may contain anything, as it accepts any Object. The required substitution string is obtained by calling the default ToString method on each Object. To supply a format string, which will be applied to each Object, in turn, use the next overload. |
Returns
Type | Description |
---|---|
System.String | String with tokens replaced, and tokens that have no corresponding object in the pnvcList collection preserved. |
ReplaceTokensFromList(String, Dictionary<String, Object>, Dictionary<String, Object>)
Given a string containing tokens of the form "^^ListKeyValue^^" where ListKeyValue is the value of a key in the pnvcList collection, which may or may not exist in the collection, replace all such tokens with the contents of the like named value in the collection.
Declaration
[Obsolete("Use the corresponding extension method.", false)]
public static string ReplaceTokensFromList(string pstrMsg, Dictionary<string, object> pdctList, Dictionary<string, object> pdctDefaults)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrMsg | String containing the message containing the substitution tokens. |
System.Collections.Generic.Dictionary<System.String, System.Object> | pdctList | A Dictionary, in which each key represents a token, and its value represents the value to be substituted for it. The Dictionary may contain anything, as it accepts any Object. The required substitution string is obtained by calling the default ToString method on each Object. To supply a format string, which will be applied to each Object, in turn, use the next overload. |
System.Collections.Generic.Dictionary<System.String, System.Object> | pdctDefaults | A Dictionary, in which each key represents a token, and its value represents the default value to be substituted for it, if there is no corresponding key in dictionary pdctList. The Dictionary may contain anything, as it accepts any Object. The required substitution string is obtained by calling the default ToString method on each Object. To supply a format string, which will be applied to each Object, in turn, use the next overload. |
Returns
Type | Description |
---|---|
System.String | String with tokens replaced, and tokens that have no corresponding object in the pnvcList OR the pdctDefaults collection preserved. |
ReplaceTokensFromList(String, Dictionary<String, Object>, Dictionary<String, Object>, String)
Given a string containing tokens of the form "^^ListKeyValue^^" where ListKeyValue is the value of a key in the pnvcList collection, which may or may not exist in the collection, replace all such tokens with the contents of the like named session object.
Declaration
[Obsolete("Use the corresponding extension method.", false)]
public static string ReplaceTokensFromList(string pstrMsg, Dictionary<string, object> pdctList, Dictionary<string, object> pdctDefaults, string pstrFormat)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrMsg | String containing the message containing the substitution tokens. |
System.Collections.Generic.Dictionary<System.String, System.Object> | pdctList | A Dictionary, in which each key represents a token, and its value represents the value to be substituted for it. The Dictionary may contain anything, as it accepts any Object. The required substitution string is obtained by calling the default ToString method on each Object. To supply a format string, which will be applied to each Object, in turn, use the next overload. |
System.Collections.Generic.Dictionary<System.String, System.Object> | pdctDefaults | A Dictionary, in which each key represents a token, and its value represents the default value to be substituted for it, if there is no corresponding key in dictionary pdctList. The Dictionary may contain anything, as it accepts any Object. The required substitution string is obtained by calling the default ToString method on each Object. To supply a format string, which will be applied to each Object, in turn, use the next overload. |
System.String | pstrFormat | Format string, acceptable to the static String.Format method, which is used to format the string representation of each object. The string must contain a "[0}" placeholder, which may occur one or more times in the format string, which is replaced by the string returned by the ToString method of each object. |
Returns
Type | Description |
---|---|
System.String | String with tokens replaced, and tokens that have no corresponding object in the pnvcList OR the pdctDefaults collection preserved. |
ReplaceTokensFromList(String, Dictionary<String, Object>, String)
Given a string containing tokens of the form "^^ListKeyValue^^" where ListKeyValue is the value of a key in the pnvcList collection, which may or may not exist in the collection, replace all such tokens with the contents o object.
Declaration
[Obsolete("Use the corresponding extension method.", false)]
public static string ReplaceTokensFromList(string pstrMsg, Dictionary<string, object> pdctList, string pstrFormat)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrMsg | String containing the message containing the substitution tokens. |
System.Collections.Generic.Dictionary<System.String, System.Object> | pdctList | A Dictionary, in which each key represents a token, and its value represents the value to be substituted for it. The Dictionary may contain anything, as it accepts any Object. The required substitution string is obtained by calling the default ToString method on each Object. To supply a format string, which will be applied to each Object, in turn, use the next overload. |
System.String | pstrFormat | Format string, acceptable to the static String.Format method, which is used to format the string representation of each object. The string must contain a "[0}" placeholder, which may occur one or more times in the format string, which is replaced by the string returned by the ToString method of each object. |
Returns
Type | Description |
---|---|
System.String | String with tokens replaced, and tokens that have no corresponding object in the pnvcList collection preserved. |
ReplaceTokensFromList(String, NameValueCollection)
Given a string containing tokens of the form "^^ListKeyValue^^" where ListKeyValue is the value of a key in the pnvcList collection, which may or may not exist in the collection, replace all such tokens with the contents of the like named value in the collection.
Declaration
[Obsolete("Use the corresponding extension method.", false)]
public static string ReplaceTokensFromList(string pstrMsg, NameValueCollection pnvcList)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrMsg | String containing the message containing the substitution tokens. |
System.Collections.Specialized.NameValueCollection | pnvcList | A NameValueCollection, in which each key represents a token, and its value represents the value to be substituted for it. |
Returns
Type | Description |
---|---|
System.String | String with tokens replaced, and tokens that have no corresponding object in the pnvcList collection preserved. |
ReplaceTokensFromList(String, NameValueCollection, NameValueCollection)
Replace place holders (markers) with the value of the corresponding form control (field), or a default value, if the field is empty and a default is designated.
Declaration
[Obsolete("Use the corresponding extension method.", false)]
public static string ReplaceTokensFromList(string pstrTemplate, NameValueCollection pnvcFields, NameValueCollection pnvcDefaults)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrTemplate | String containing a template containing the text and place markers. |
System.Collections.Specialized.NameValueCollection | pnvcFields | NameValueCollection containing the form control (field) values. |
System.Collections.Specialized.NameValueCollection | pnvcDefaults | NameValueCollection containing the form control (field) or token default values. Default values are optional. If omitted, the method substitutes an empty string. |
Returns
Type | Description |
---|---|
System.String | String containing the text in the template, with all tokens formatted with default endings replaced by the contents of the corresponding, and like named, control (field) on the input form. Tokens bounded by "##" are replaced by strings from the Session variables collection. The same defaults collection is used for both. |
StrFill(Char, Int32)
Return a string composed of a specified number of a specified character.
Declaration
public static string StrFill(char pchr, int pintCount)
Parameters
Type | Name | Description |
---|---|---|
System.Char | pchr | Specify the character with which to fill the string, which may be anything except the null character. |
System.Int32 | pintCount | Specify how many characters should be in the returned string. |
Returns
Type | Description |
---|---|
System.String | If the function succeeds, the return value is a string composed of a specified number of a specified character. If pintCount is less than 1, the return value is a null reference. If |
Remarks
Reserving both the empty string and the null reference for different input conditions permits complete diagnostic reporting without throwing any exceptions.
Truncate(String, Int32)
Supply the missing Truncate function to members of the String class.
Declaration
[Obsolete("Use the corresponding extension method.", false)]
public static string Truncate(string pstrSource, int pintMaxLength)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrSource | String to truncate, if it is longer than pintMaxLength. A null string is treated as an empty string, and the return value for either is an empty string. |
System.Int32 | pintMaxLength | Desired maximum length of the returned string. If pstrSource is longer than pintMaxLength characters, the first pintMaxLength are returned. Otherwise, the whole string is returned. If pintMaxLength is less than or equal to zero, an empty string is returned. |
Returns
Type | Description |
---|---|
System.String | If the string length is less than or equal to the specified maximum length, the whole string is returned. Otherwise, the first pintMaxLength characters are returned. Regardless, the return value is a new System.String object. |
TruncateValueToOneLine(Object, Int32)
The name says it pretty well; truncate the string representation of
pobjValueToDisplay
so that it contains only the
first line of text.
Declaration
public static string TruncateValueToOneLine(object pobjValueToDisplay, int pintMaxLengthOfOneLine = 132)
Parameters
Type | Name | Description |
---|---|---|
System.Object | pobjValueToDisplay | Pass in the object for which a string representation is required. |
System.Int32 | pintMaxLengthOfOneLine | When specified, this optional value is the maximun number of characters to display. This limit applies to all string represenntations, regardless of whether they contain embedded newline characters that already cause them to be truncated. |
Returns
Type | Description |
---|---|
System.String | The return value is a string that occupies no more than one line. |