String Extension

A most complete and elaborately constructed extension on string for .NET. The following is a list of all string operations supported by the first preview of .NET extension (overloads not included). Tens of new methods have been added by a new version.

Basics

IsNullOrEmpty

Indicates whether this string instance is null or empty. 

 

IsNullOrEmpty

OrBlank

Indicates whether the this string instance is null, empty or contains no character other than blank space.

 

Scan

Replaces the format item in this string with the string representation of a corresponding object in a specified array.

Copy

Creates a new string instance with the same value as the current one.

 

Equals

Determines whether this string instance and another specified string instance have the same value with case and trim options.

 

In

Determines whether this string instance is in a sequence of strings.

OnlyASCIIs

Gets a value indicating whether this string instance contains only ASCII characters.

 

OnlyASCIILetters

AndDigits

Gets a value indicating whether this string instance contains only ASCII letters and digits (namely a-z, A-Z, 0-9).

 

OnlyLetters

AndDigits

Gets a value indicating whether this string instance contains only letters and digits. Whether a character is a letter or a number is determined by char.IsLetter and char.IsDigit methods.

    

Remove

Remove

Removes a new string in which all occurrences of the specified substrings/characters are removed from the current string.

RemoveAfter

RemoveBefore

RemoveAfterLast

RemoveBeforeLast

Returns a copy of the current string with all characters after/before the first/last occurrence of a specified delimiter removed. The delimiter may be removed as well.

Contains

Contains

Returns a value indicating whether the specified string value occurs within this string. A System.StringComparison parameter specifies options for string comparison. A Boolean parameter indicates the search direction.

 

ContainsAll

Determines whether this string instance contains all the specified strings.

 

ContainsAll

Sequentially

Determines whether this string instance contains all the specified strings sequentially.

 

ContainsAny

Determines whether this string instance contains any of the specified strings.

Contains

ByOption

Determines whether this string instance contains any/all/the first one/the last one of the strings specified in a System.StringSeekOption object.

    

IndexOf

IndexOf

LastIndexOf

Reports the index of the first/last character satisfying the specified predicate.

IndexOfAll

Reports the indexes of the first occurrences of several specified strings in this string instance.

 

IndexOfAny

LastIndexOfAny

Reports the index of the first/last occurrence of any of the specified strings in this string instance.

 

IndexOf

ByOption

Reports the first occurrence's index of any/all/the first one/the last one of the target strings specified in the System.StringSeekOption object within a specified segment of this string instance.

    

Split

BiSplit

Splits this string into two parts at the position where the first occurrence of separator is found. This is a pretty useful when spliting an attribute-value string like "company: Microsoft".

Split

Returns a string array that contains the substrings in this instance that are delimited by characters satifying the specified predicate. Additional options, such as the search starting position, are available.

Split

Splits this string in some special way,typically separating ASCII parts from non-ASCII parts.

Split

Splits this string instance into a two-dimensional jagged array string[][]. For example, you may split "ab,c,defg;h,ijk;l,mn,op,q" with ',' as the separator1 and ';' the separator2 The result is three arrays of strings, the first one be string[] {"ab", "c", "defg"}.

 

SplitToLines

Spilts the current string instance to lines represented by a string array.

Split

ByInitials

Splits this string by upper letters. For example, string "ABigAppleTree" will be split as "A Big Apple Tree".

Split

Preserving

Separators

Returns substrings of this string instance delimited by elements in an array of Unicode characters. This method works like the Split method, however, Split discards the separators while this method keeps them.

Concatenation

Concat

Concates the current sequence of strings into a single string.

Retrieval

RetrieveFirst

Retrieves a substring represented by a System.Substring object from this string instance.

Retrieve

Retrieves substrings represented by System.Substring objects from this string instance.

GetEnumerator

Gets an enumerator that supports simple iteration of substrings in this string instance. A typical use is to iterate all HTML tags in HTML code.

    

Start & End

StartsWith

Gets a value indicating whether a substring starting at a specified position of the current string instance starts with the target string specified by value.

StartsWithAny

EndsWithAny

Determines whether the beginning/end of this string instance matches any element of the specified string sequence.

TrimStart

TrimEnd

Removes the beginning/end part of this string instance if it exists in the specified string sequence trims.

    

Substring

Substring

Retrieves a substring from this string instance. The substring starts at the position before/after the first occurrence of a substring specified by startIndicator and ends at the position before/after the first occurrence of a substring specified by endIndicator.

CountOf

Substring

Gets the number of occurrences of a specified substring in the current string instance.

    

Modification

Reverse

Returns a copy of the reversed version of this string instance.

LowercaseInit

UppercaseInit

Returns a copy of this string instance with the first Unicode character converted to its lowercase/uppercase equivalent.

InsertBefore

Initials

Inserts a specified character before all upper letters in this string.

 

InsertSpace

BeforeInitials

Inserts a single space before all initials (upper letters) in this string.

 

Shorten

Cuts short this string instance if it execeeds a given length and then attach it with a tail. For a typical example, "Microsoft Visual Studio" is shortened to "Microsoft Visua..." when length is set 15 and tail is set "...".

 

Decorate

Decorates this string with the repetition of specified characters. For example, decorating "abc" as "--abc***" when using "-" as the decoration character at the left side and "*" at the right side, or as "    abc  " when using a space as the decoration character at both sides.

Data

ToBooleanArray

ToSByteArray

ToByteArray

ToInt16/32/64Array

ToUInt16/32/64Array

ToSingleArray

ToDoubleArray

ToDateTimeArray

Converts a string representation of values delimited by separator to equivalent true values.

 

Taking ToUInt64Array for example, input "100, 200, 300" with comma ',' as the separator will return a 64-bit unsigned integer array {100, 200, 300}.

 

Also Taking ToBooleanArray for example, input "true false true" with space ' ' as the separator will return a Boolean array {true, false, true}

 

ToBoolean

ToSByte

ToByte

ToInt16/32/64

ToUInt16/32/64

ToSingle

ToDouble

ToDateTime

Provides shortcuts to convert the specified System.String representation of a value of some type to its equivalent value of that type.

Others

GetInteger

Gets the first integer consisting of ASCII digits in this string instance. For example, the first integer in string "There are 100 students and 5 classes in this school." is 100.

 

GetIntegers

Gets all integers consisting of ASCII digits in this string instance. For example, the integers in string "There are 100 students and 5 classes in this school." are 100 and 5.

 

GetHashCode64

Serves as a hash function that returns a 64-bit integer hash code for this string instance.

HexEncode

Encodes non-ASCII chars in this string by their equivalent hex representations. For example, "http://www.hudong.com/wiki/电子垃圾" will be translated to "http://www.hudong.com/wiki/%E7

%94%B5%E5%AD%90%E5%9E%83%E5%9C%BE".

 

HexDecode

Decodes hex representations in this string to their equivalent chars. For example, "http://www.hudong.com/wiki/%E7%94%B5%E5

%AD%90%E5%9E%83%E5%9C%BE" will be translated to "http://

www.hudong.com/wiki/电子垃圾".

    

String Collection

ToHashSet

Converts the current string sequence to a hashset.

TrimAll

TrimStartAll

TrimEndAll

Removes all leading and trailing occurrences of a set of characters (typically the whit spaces) specified in an array from every string in this string array/list.

Last edited Sep 15, 2012 at 5:25 AM by rivermsfly, version 2

Comments

No comments yet.