Home > Services > DXCore Services – String Utilities

DXCore Services – String Utilities

September 19th, 2011

The String Utilities DXCore service (accessed via the CodeRush.StrUtil object) provides utility methods for manipulating single string, multi-line texts, and string arrays.

Here are the methods of this service:

Method name

Description

AddExpressionTagsToText (String) Adds expression tags to the given string. You can use the RemoveExpressionTags method to delete expression tags from the text.
AddLineTerminatorIfNecessery (String) Verifies if the given string ends with a line terminator, and then adds it to the end of the string if it does not exist.
AddLinkTagsToText(String) Adds link tags to the given string. You can use the RemoveLinkTags method to delete link tags from the text.
AddMultiLinkTagsToText (String, string[]) Adds multi-link tags to the given string. You can use the RemoveMultiLinkTags method to delete multi-link tags from the text.
AddNameTagsToText(String) Adds name tags to the given string. You can use the RemoveNameTags method to delete name tags from the text.
AddQuotes(String) Adds double quotes (“) to the given string.
AddTagsToText(String) Adds default tags to the given string. You may use the RemoveTextTags(ref string) method to delete tags from the text.
AddTagsToText(String, String, String) Adds specified tags to the text. You can use the RemoveTextTags method to delete tags from the text.
AddTypeTagsToText(String) Adds type tags to the given string. You can use the RemoveTypeTags method to delete name tags from the text.
BuildCSV(string[]) Creates a comma-separated string from the given string array.
BuildParamString(string[]) Creates a parameter with a comma-separated string from the given string array. The result is a comma-separated string wrapped by parens.
CharIn(Char, Char, Char) Verifies if the given character is in the specified range.
CharIn(Char, char[]) Verifies if the given character is in the specified array of characters.
CharIn(Char, String) Verifies if the given character is in the specified string.
CloneStringCollection (StringCollection) Creates a copy of a string collection instance.
CollectionFromString(String) Creates a string collection from the given string separated by line terminators.
ConvertToCSV(string[]) Converts the given string array to a comma-separated string.
ConvertToCSV(string[], Boolean) Converts the given string array to a comma-separated string. If the quoteCommas parameter is true, any values in the given string array containing commas are added inside double-quotes.
CountLines(String) Returns the number of lines in the given text. (Note: an empty string counts as one line). This function uses Regex to find line terminators.
CountLines(String, LineTerminator) Returns the number of lines in the given text using the specified line terminator. (Note: an empty string counts as one line).
DecodeName(String) Converts the special character-codes to the original characters (‘\’, ‘/’, ‘:’, ‘*’, ‘?’, ‘”‘, ‘<‘, ‘>’, ‘|’, ‘_’). Use with the EncodeName method.
DecodeText(String) Converts the special line break tags ($LineBreak$) into a cariage-return/line-break characters (\r\n). Used internally.
DuplicateArray(string[]) Creates a copy of the given string array.
EncodeName(String) Converts the special characters (‘\’, ‘/’, ‘:’, ‘*’, ‘?’, ‘”‘, ‘<‘, ‘>’, ‘|’, ‘_’) to the special character-codes. Use with the DecodeName method.
EncodeText(String) Converts different types of a line terminators to the special line break tag ($LineBreak

$). Used internally.

EndsWithLineTerminator (String) Verifies if the given string ends with a line terminator.
ExtractStartingWord(String) Extracts the first word from the given string.
FillArray(String, Int32) Creates an array of strings from the specified text.
FirstChar(String) Returns the first character of the given text, if any.
FirstChar(String, Boolean) Returns the first character of the given text, if any. Optionally, throws an exception if the given string is null or empty.
FormatForInsertText(String) Converts a string with carriage-return/line-feeds to line feeds only, preventing the EditPoint’s InsertText method from doubling-up the inserted lines. Note that it is hidden from Intellisense.
FormatForTextBox(String) Converts a string with line feeds to a string with carriage-return/line feeds. Note that it is hidden from Intellisense.
GetClosingWhiteSpace(String) Returns the closing white space (tabs and spaces) for the specified text.
GetClosingWhiteSpace(String, Int32) Returns the closing white space characters (tabs and spaces) on the given text.
GetClosingWhiteSpaceCharCount (String) Returns the number of closing white space characters (tabs and spaces) on the given text.
GetFirstLineTerminatorIndex (String) Returns the index of the first line terminator in the given string or -1 if the given string does not have a line terminator.
GetLastLineTerminator(String) Returns the last line terminator in the given string or empty TagText if the given string does not end with a line terminator.
GetLastLineTerminatorIndex (String) Returns the index of the last line terminator in the given string or -1 if the given string does not end with the line terminator.
GetLeadingWhiteSpace(String) Returns the leading white space (tabs and spaces) for the given text.
GetLeadingWhiteSpace(String, Int32) Returns the leading white space characters (tabs and spaces) on the given text.
GetLeadingWhiteSpaceCharCount (String) Returns the number of the leading white space characters (tabs and spaces) on the given text.
GetLineEndIndex(ArrayList, String, Int32) Returns the end index of the specified line number in the given text separated by the specified line terminators passed as an array list. Note that it is hidden from Intellisense.
GetLineEndIndex(String, Int32) Returns the end index of the specified line number in the given text.
GetLineEndIndex(String, Int32, LineTerminator) Returns the end index of the specified line number in the given text using the specified line terminator.
GetLineEndPoint(String, Int32) Returns the source point indicating the end of the given string.
GetLineEndPoint(String, Int32, LineTerminator) Returns the source point indicating the end of the given text ending with the specified line terminator.
GetLineLength(String, Int32) Returns the length of the specified line in the given text.
GetLineLength(String, Int32, LineTerminator) Returns the length of the specified line in the given text separated by the specified line terminator.
GetLineStartIndex(String, Int32) Returns the starting index of the specified line in the given text.
GetLineStartIndex(String, Int32, LineTerminator) Returns the starting index of the specified line in the given text using the passed-in line terminator.
GetLineTerminator(String) Returns the line terminator used in the given text.
GetLineTerminator(String, Int32) Returns the line terminator used at the specified index in the given text.
GetLineTerminatorChar(Char) Returns a line terminator for the given character.
GetLineTerminatorChar (LineTerminatorChar) Returns a character for the given line terminator.
GetLineTerminatorLength (LineTerminator) Returns the length (in characters) of the given line terminator.
GetLineTerminatorRegex Returns the regular expression that matches all line terminators.
GetLineTerminators(String) Return the list of line terminators used in the given text.
GetLineTerminators(String, Int32) Return the list of line terminators used in the given text starting from the specified index.
GetLineTerminatorText (LineTerminator) Returns the string that represents the given line terminator.
GetLineText(String, Int32) Returns the line of text from the given text at the specified line index.
GetLineText(String, Int32, LineTerminator) Returns the line of text from the given text separated by the specified line terminator at the specified line index.
GetParameters(String) Returns the text between open and close parens, and removes the parameter block from the command. For example, given the command of “Say(Hello)”, this method returns “Hello” string and adjusts the command, so it becomes “Say”.
GetParametersFromText(String) Returns the text of parameters (inside parens).
GetSharedStringBuilder Returns a SharedStringBuilder from an internal pool.
GetSubstring(String, Int32, Int32) Returns the substring for the given text, using the given start and end indices. Returns String.Empty if the passed arguments are invalid.
GetSubstring(String, Int32, Int32, Boolean) Returns the substring for the given text, using the given start and end indices. Returns String.Empty if the passed arguments are invalid. The throwOnError parameter determines if an exception should be thrown in case invalid arguments.
GetText(ArrayList, String, Int32, Int32) Returns the text separated by the specified line terminators at the given start and end lines.
GetText(String, Int32, Int32) Returns the text at the given start and end lines.
GetText(String, Int32, Int32, Int32, Int32) Returns the text at the given coordinates (start line, start offset, end line, end offset).
GetText(String, SourcePoint, SourcePoint) Returns the text at the given coordinates (start source point, end source point).
GetText(String, SourceRange) Returns the text at the given source range coordinates.
GetTextLength(String, Int32, Int32, Int32, Int32) Returns the length of text at the given coordinates (start line, start offset, end line, end offset).
GetTextLength(String, SourcePoint, SourcePoint) Returns the length of text at the given coordinates (start source point, end source point).
GetTextTags(String, String, String) Returns the tags from the given text. This method allows you to get the text that is marked with the tags using the AddTagsToText method. The method does not remove the tags from the given text.
GetUniqueName(String, IList) Returns the string based on the passed base name which is unique in the given list. The returned string is the passed base name with a trailing number, starting with 1 and incrementing until the return value is unique in the given list.
GetWhiteSpaceCount(String) Return the count of all white space characters in the given string.
GuessLineTerminator(String) Tries to guess what line terminator is used in the given text. If there are mixed line terminators then this function returns only the first found line terminator.
InsideParens(String, String) Returns true if the given leftText contains more open parens than close parens, or if the given rightText contains more close parens than open parens.
IsEndLineTerminatorNeeded (String, SourcePoint) Returns true if an end line terminator is required to be added to the text that is going to be inserted at the specified source point.
IsEndLineTerminatorNeeded (TextDocument, SourcePoint) Returns true if an end line terminator is required to be added to the text that is going to be inserted at the specified source point in the specified text document.
IsNullOrEmpty(String) Determines if the given string is null or an empty string, containing no text.
IsNumber(String) Determines if the given string represents an integer.
IsStartLineTerminatorNeeded (String, SourcePoint) Returns true if a start line terminator is required to be added to the text that is going to be inserted at the specified source point.
IsStartLineTerminatorNeeded (TextDocument, SourcePoint) Returns true if a start line terminator is required to be added to the text that is going to be inserted at the specified source point in the specified text document.
JoinLines(string[]) Combines the given string array into a single string separated by an MS-DOS (carriage-return\line-feed) line separator. A line terminator will not be added to the resulting string.
JoinLines(string[], Boolean) Combines the given string array into a single string separated by an MS-DOS (carriage-return\line-feed) line separator. A boolean parameter specifies whether a line terminator should be added at the end of the resulting string.
JoinLines(string[], LineTerminator) Combines the given string array into a single string separated by the specified line terminator. A line terminator will not be added to the resulting string.
JoinLines(string[], LineTerminator, Boolean) Combines the given string array into a single string separated by the specified line terminator. A boolean parameter specifies whether a line terminator should be added at the end of the resulting string.
JoinLines(StringCollection) Combines the given string collection into a single string separated by an MS-DOS (carriage-return\line-feed) line separator. A line terminator will not be added to the resulting string.
JoinLines(StringCollection, Boolean) Combines the given string collection into a single string separated by an MS-DOS (carriage-return\line-feed) line separator. A boolean parameter specifies whether a line terminator should be added at the end of the resulting string.
JoinLines(StringCollection, LineTerminator) Combines the given string collection into a single string separated by the specified line terminator. A line terminator will not be added to the resulting string.
JoinLines(StringCollection, LineTerminator, Boolean) Combines the given string collection into a single string separated by the specified line terminator. A boolean parameter specifies whether a line terminator should be added at the end of the resulting string.
LastChar(String) Returns the last character from the given string.
LastChar(String, Boolean) Returns the last character from the given string. Optionally throws an exception if the given string is null or empty.
LeftString(String, Int32) Returns a part of the given string of the specified length from the left.
LeftString(String, Int32, Boolean) Returns a part of the given string of the specified length from the left. Optionally throws an exception if the given string is null or empty, or an incorrect count is specified.
MustEndWith(String, String) Ensures that the given text ends with the specified suffix.
MustStartWith(String, String) Ensures that the given text starts with the specified suffix.
OffsetToTabColumn(String, Int32, Int32) Calculates the column position in the given text for the specified character offset.
ParenScore(String) Returns a negative number if there are more open parens than close parens. Returns a positive number if there are more close parens than open parens.
ParseCSV(String) Parses the given comma separated string into a string array.
ParseCSV(String, Boolean) Parses the given comma separated string into a string array. Optionally handles text command quotes (“” and “”) as well as regular double quotes.
PasteText(String, Int32, Int32, String) Inserts the specified string into the given text at the specified line and offset.
PasteText(String, Int32, String) Inserts the specified string into the given text at the specified index.
PasteText(String, SourcePoint, String) Inserts the specified string into the given text at the specified source point.
PasteText(String, String) Inserts the specified string before the given text.
RangeOf(String, Int32, String) Returns the source range of the specified string in the given text starting from the specified index.
RangeOf(String, SourcePoint, String) Returns the source range of the specified string in the given text at the specified source point.
RemoveExpressionTags(String) Removes the expression tags from the given text that were added by the AddExpressionTagsToText method.
RemoveLastLineTerminator (String) Removes the last line terminator from the given string.
RemoveLeadingDigits(String) Removes any digits from the start of the given string.
RemoveLeadingLineTerminator (String) Removes the leading line terminator from the given string.
RemoveLinkTags(String) Removes the link tags from the given text that were added by the AddLinkTagsToText method.
RemoveMultiLinkTags(String) Removes the multi-link tags from the given text that were added by the AddMultiLinkTagsToText method.
RemoveNameTags(String) Removes the name tags from the given text that were added by the AddNameTagsToText method.
RemoveQuotes(String) Remove the double quotes (“) from the given string.
RemoveTagsForPreview(String) Removes all redundant text tags and text commands from the given text.
RemoveText(String, Int32, Int32) Removes the text at the specified start and end index.
RemoveText(String, Int32, Int32, Int32) Removes the text starting from the specified line and offset of the specified length.
RemoveText(String, SourcePoint, SourcePoint) Removes the text at the specified start and end source point coordinates.
RemoveTextTags(String) Removes default tags from the given text. This method allows deleting tags that were added by the AddTagsToText method.
RemoveTextTags(String, String, String) Removes the specified tags from the given text. This method allows deleting tags that were added by the AddTagsToText method.
RemoveTextTags(String, String, String, Boolean) Removes the specified tags from the given text. This method allows deleting tags that were added by the AddTagsToText method. Optionally checks for parameters inside parens.
RemoveTrailingDigits(String) Removes digits from the end of the given string.
RemoveTrailingLineTerminator (String) Removes the trailing line terminator from the given string.
RemoveTypeTags(String) Removes the type tags from the given text that were added by the AddTypeTagsToText method.
ReplaceInnerText(String, String, String, ReplaceTextDelegate) Searches for all occurrences of the given text which starts with the specified start substring and ends with the specified end substring, then replaces each found occurrence using the text replacer delegate.
RightString(String, Int32) Returns a part of the given string of the specified length from the right.
RightString(String, Int32, Boolean) Returns a part of the given string of the specified length from the right. Optionally throws an exception if the given string is null or empty, or a wrong count is specified.
SeparateParams(String, String) Splits the given string into a command and its parameters. For example, given the string of “Say(Hello)”, this method returns the “Hello” string as an out parameter and adjusts the command, so it becomes “Say”.
SeparateParams(String, string[]) Splits the given string into a command and its parameters. Parameters are returned as a string array if they are separated by commas.
SeparateValues(string[], String) Converts the given string array into a single string. Strings from the given array are separated by the specified separator.
SeparateValues(string[], String, Boolean) Converts the given string array into a single string. Strings from the given array are separated by the specified separator. Optionally adds the double quotes around the items that contain the separator.
SeparateValues(StringCollection, String) Converts the given string collection into a string. Strings from the given collection are separated by the specified separator.
SeparateValues(StringCollection, String, Boolean) Converts the given string collection into a string. Strings from the given collection are separated by the specified separator. Optionally adds the double quotes around the items that contain the separator.
SetText(String, SourceRange[], String) Changes the text inside the given string within the specified source ranges.
SetText(String, SourceRange[], String, SourceRange[]) Changes the text inside the given string within the specified source ranges.
SetText(String, SourceRange[], string[]) Changes the text inside the given string within the specified source ranges.
SetText(String, SourceRange[], string[], SourceRange[]) Changes the text inside the given string within the specified source ranges.
SetText(String, SourceRangeCollection, String) Changes the text inside the given string within the specified source ranges.
SetVariables(String) Calls the Set string provider once for each comma-delimited assignment in the form of “variable=value” inside the specified string. White space, if specified, will also be assigned to the variable.
ShowWhitespace(String, Int32) Converts the whitespace characters in the given string into the characters that represent whitespace.
ShowWhitespace(string[], Int32) Converts the whitespace characters in the given string array into the characters that represent whitespace.
SplitCodeLine(String, Int32, String, String) Splits the given code into the left and right segments at the specified character offset.
SplitLines(String) Splits the given string containing line terminators into a string array. If, after splitting, the last entry is empty, it is removed from the result.
SplitLines(String, Boolean) Splits the given string containing line terminators into a string array. Optionally removes the last entry from the result if it is empty.
StartsWithLineTerminator(String) Verifies if the given string starts with a line terminator.
SubstringToLower(String, Int32, Int32) Converts the specified part of the given string to the lower case string.
SubstringToUpper(String, Int32, Int32) Converts the specified part of the given string to the upper case string.
TabColumnToOffset(String, Int32, Int32) Converts the column in the given text line into a character offset.
TabifyLine(String, Int32) Replaces the space characters in the given text line with the tab characters using the given tab size.
TabifyLine(String, Int32, Int32) Replaces the space characters in the given text line with the tab characters using the given tab size starting from the specified index.
TabifyLine(String, Int32, Int32, Int32) Replaces the space characters in the given text line with the tab characters using the given tab size starting from the specified index with the specified length.
TabifyLines(string[], Int32) Replaces the space characters in the given string array with the tab characters using the given tab size.
TabifyLines(string[], Int32, Int32, Int32) Replaces the space characters in the given string array with the tab characters using the given tab size starting from the specified index with the specified length.
TextToXML(String) Converts the given text into XML (replacing special characters with XML analogs (quot; amp; lt; gt;), returning the converted value as a string.
ToIndex(Int32, String, SourcePoint) Returns the index of the specified source point in the given text starting from the specified line number.
ToIndex(String, SourcePoint) Returns the index of the specified source point in the given text.
ToSourcePoint(ArrayList, String, Int32) Returns the source point of the specified index in the given text separated by the specified line terminators.
ToSourcePoint(String, Int32) Returns the source point of the specified index in the given text.
ToSourceRange(ArrayList, String, Int32, Int32) Returns the source range of the specified start and end indices in the given text separated by the specified line terminators.
ToSourceRange(String, Int32, Int32) Returns the source range of the specified start and end indices in the given text.
TrimLinesEnd(String) Trims the end of each line inside the given text.
UntabifyLine(String, Int32) Replaces the tab characters in the given string with the space characters using the given tab size.
UntabifyLine(String, Int32, Int32) Replaces the tab characters in the given string with the space characters using the given tab size starting from the specified index.
UntabifyLine(String, Int32, Int32, Int32) Replaces the tab characters in the given string with the space characters using the given tab size starting from the specified index with the specified length.
UntabifyLines(string[], Int32) Replaces the tab characters in the given string array with the space characters using the given tab size.
UntabifyLines(string[], Int32, Int32, Int32) Replaces the tab characters in the given string array with the space characters using the given tab size starting from the specified index with the specified length.
—–
Products: DXCore
Versions: 11.1 and up
VS IDEs: any
Updated: Sep/19/2011
ID: D114

Similar Posts: