C# 클래스 Westwind.Utilities.StringUtils

String utility class that provides a host of string related operations
파일 보기 프로젝트 열기: RickStrahl/WestwindToolkit

공개 메소드들

메소드 설명
Base36Decode ( string input ) : long

Decodes a base36 encoded string to an integer

Base36Encode ( long value ) : string

Encodes an integer into a string by mapping to alpha and digits (36 chars) chars are embedded as lower case Example: 4zx12ss

BinHexToBinary ( string hex ) : byte[]

Turns a BinHex string that contains raw byte values into a byte array

BinaryToBinHex ( byte data ) : string

Converts a byte array into a BinHex string. BinHex is two digit hex byte values squished together into a string.

BytesToString ( byte buffer, Encoding encoding = null ) : string

Converts a byte array to a stringUtils

CountLines ( string s ) : int

Returns a line count for a string

ExtractString ( string source, string beginDelim, string endDelim, bool caseSensitive = false, bool allowMissingEndDelimiter = false, bool returnDelimiters = false ) : string

Extracts a string from between a pair of delimiters. Only the first instance is found.

FromCamelCase ( string camelCase ) : string

Tries to create a phrase string from CamelCase text. Will place spaces before capitalized letters. Note that this method may not work for round tripping ToCamelCase calls, since ToCamelCase strips more characters than just spaces.

GetLines ( string s ) : string[]

Parses a string into an array of lines broken by \r\n or \n

GetProperty ( string propertyString, string key ) : string

Retrieves a value from an XML-like string

GetUrlEncodedKey ( string urlEncoded, string key ) : string

Retrieves a value by key from a UrlEncoded string.

Inlist ( string s ) : bool

Determines if a string is contained in a list of other strings

LogString ( string output, string filename, Encoding encoding = null ) : void

Simple Logging method that allows quickly writing a string to a file

NewStringId ( ) : string

Creates short string id based on a GUID hashcode. Not guaranteed to be unique across machines, but unlikely to duplicate in medium volume situations.

NormalizeIndentation ( string code ) : string

Strips any common white space from all lines of text that have the same common white space text. Effectively removes common code indentation from code blocks for example so you can get a left aligned code snippet.

ParseDecimal ( string input, decimal defaultValue = 0M, IFormatProvider numberFormat = null ) : decimal

Parses an string into an decimal. If the value can't be parsed a default value is returned instead

ParseInt ( string input, int defaultValue, IFormatProvider numberFormat = null ) : int

Parses an string into an integer. If the value can't be parsed a default value is returned instead

ProperCase ( string Input ) : string

Return a string in proper Case format

RandomString ( int size, bool includeNumbers = false ) : string

Creates a new random string of upper, lower case letters and digits. Very useful for generating random data for storage in test data.

ReplaceString ( string origString, string findString, string replaceString, bool caseInsensitive ) : string

Replaces a substring within a string with another substring with optional case sensitivity turned off.

ReplaceStringInstance ( string origString, string findString, string replaceWith, int instance, bool caseInsensitive ) : string

String replace function that supports replacing a specific instance with case insensitivity

Replicate ( char character, int charCount ) : string

Replicates a character n number of times and returns a string

Replicate ( string input, int charCount ) : string

Replicates an input string n number of times

SetProperty ( string propertyString, string key, string value ) : string

SetUrlEncodedKey ( string urlEncoded, string key, string value ) : string

Allows setting of a value in a UrlEncoded string. If the key doesn't exist a new one is set, if it exists it's replaced with the new value.

StringToBytes ( string text, Encoding encoding = null ) : byte[]

Converts a string into bytes for storage in any byte[] types buffer or stream format (like MemoryStream).

StringToStream ( string text, Encoding encoding = null ) : Stream

Creates a Stream from a string. Internally creates a memory stream and returns that.

StripNonNumber ( string input ) : string

Strips all non digit values from a string and only returns the numeric string.

TerminateString ( string value, string terminator ) : string

Terminates a string with the given end string/character, but only if the value specified doesn't already exist and the string is not empty.

TextAbstract ( string text, int length ) : string

Returns an abstract of the provided text by returning up to Length characters of a text string. If the text is truncated a ... is appended.

ToCamelCase ( string phrase ) : string

Takes a phrase and turns it into CamelCase text. White Space, punctuation and separators are stripped

TrimStart ( string text, string textToTrim, bool caseInsensitive ) : string

Trims a sub string from a string

TrimTo ( string value, int charCount ) : string

Trims a string to a specific number of max characters

UrlDecode ( string text ) : string

UrlDecodes a string without requiring System.Web

UrlEncode ( string text ) : string

UrlEncodes a string without the requirement for System.Web

UrlEncodePathSafe ( string text ) : string

Encodes a few additional characters for use in paths Encodes: . #

비공개 메소드들

메소드 설명
Empty ( object text ) : bool
Empty ( string text ) : bool
ParseHexChar ( char c ) : int

메소드 상세

Base36Decode() 공개 정적인 메소드

Decodes a base36 encoded string to an integer
public static Base36Decode ( string input ) : long
input string
리턴 long

Base36Encode() 공개 정적인 메소드

Encodes an integer into a string by mapping to alpha and digits (36 chars) chars are embedded as lower case Example: 4zx12ss
public static Base36Encode ( long value ) : string
value long
리턴 string

BinHexToBinary() 공개 정적인 메소드

Turns a BinHex string that contains raw byte values into a byte array
public static BinHexToBinary ( string hex ) : byte[]
hex string BinHex string (just two byte hex digits strung together)
리턴 byte[]

BinaryToBinHex() 공개 정적인 메소드

Converts a byte array into a BinHex string. BinHex is two digit hex byte values squished together into a string.
public static BinaryToBinHex ( byte data ) : string
data byte Raw data to send
리턴 string

BytesToString() 공개 정적인 메소드

Converts a byte array to a stringUtils
public static BytesToString ( byte buffer, Encoding encoding = null ) : string
buffer byte raw string byte data
encoding System.Text.Encoding Character encoding to use. Defaults to Unicode
리턴 string

CountLines() 공개 정적인 메소드

Returns a line count for a string
public static CountLines ( string s ) : int
s string string to count lines for
리턴 int

ExtractString() 공개 정적인 메소드

Extracts a string from between a pair of delimiters. Only the first instance is found.
public static ExtractString ( string source, string beginDelim, string endDelim, bool caseSensitive = false, bool allowMissingEndDelimiter = false, bool returnDelimiters = false ) : string
source string Input String to work on
beginDelim string
endDelim string ending delimiter
caseSensitive bool
allowMissingEndDelimiter bool
returnDelimiters bool
리턴 string

FromCamelCase() 공개 정적인 메소드

Tries to create a phrase string from CamelCase text. Will place spaces before capitalized letters. Note that this method may not work for round tripping ToCamelCase calls, since ToCamelCase strips more characters than just spaces.
public static FromCamelCase ( string camelCase ) : string
camelCase string
리턴 string

GetLines() 공개 정적인 메소드

Parses a string into an array of lines broken by \r\n or \n
public static GetLines ( string s ) : string[]
s string String to check for lines
리턴 string[]

GetProperty() 공개 정적인 메소드

Retrieves a value from an XML-like string
public static GetProperty ( string propertyString, string key ) : string
propertyString string
key string
리턴 string

GetUrlEncodedKey() 공개 정적인 메소드

Retrieves a value by key from a UrlEncoded string.
public static GetUrlEncodedKey ( string urlEncoded, string key ) : string
urlEncoded string UrlEncoded String
key string Key to retrieve value for
리턴 string

Inlist() 공개 정적인 메소드

Determines if a string is contained in a list of other strings
public static Inlist ( string s ) : bool
s string
리턴 bool

LogString() 공개 정적인 메소드

Simple Logging method that allows quickly writing a string to a file
public static LogString ( string output, string filename, Encoding encoding = null ) : void
output string
filename string
encoding System.Text.Encoding if not specified used UTF-8
리턴 void

NewStringId() 공개 정적인 메소드

Creates short string id based on a GUID hashcode. Not guaranteed to be unique across machines, but unlikely to duplicate in medium volume situations.
public static NewStringId ( ) : string
리턴 string

NormalizeIndentation() 공개 정적인 메소드

Strips any common white space from all lines of text that have the same common white space text. Effectively removes common code indentation from code blocks for example so you can get a left aligned code snippet.
public static NormalizeIndentation ( string code ) : string
code string
리턴 string

ParseDecimal() 공개 정적인 메소드

Parses an string into an decimal. If the value can't be parsed a default value is returned instead
public static ParseDecimal ( string input, decimal defaultValue = 0M, IFormatProvider numberFormat = null ) : decimal
input string
defaultValue decimal
numberFormat IFormatProvider
리턴 decimal

ParseInt() 공개 정적인 메소드

Parses an string into an integer. If the value can't be parsed a default value is returned instead
public static ParseInt ( string input, int defaultValue, IFormatProvider numberFormat = null ) : int
input string Input numeric string to be parsed
defaultValue int Optional default value if parsing fails
numberFormat IFormatProvider
리턴 int

ProperCase() 공개 정적인 메소드

Return a string in proper Case format
public static ProperCase ( string Input ) : string
Input string
리턴 string

RandomString() 공개 정적인 메소드

Creates a new random string of upper, lower case letters and digits. Very useful for generating random data for storage in test data.
public static RandomString ( int size, bool includeNumbers = false ) : string
size int The number of characters of the string to generate
includeNumbers bool
리턴 string

ReplaceString() 공개 정적인 메소드

Replaces a substring within a string with another substring with optional case sensitivity turned off.
public static ReplaceString ( string origString, string findString, string replaceString, bool caseInsensitive ) : string
origString string String to do replacements on
findString string The string to find
replaceString string The string to replace found string wiht
caseInsensitive bool If true case insensitive search is performed
리턴 string

ReplaceStringInstance() 공개 정적인 메소드

String replace function that supports replacing a specific instance with case insensitivity
public static ReplaceStringInstance ( string origString, string findString, string replaceWith, int instance, bool caseInsensitive ) : string
origString string Original input string
findString string The string that is to be replaced
replaceWith string The replacement string
instance int Instance of the FindString that is to be found. if Instance = -1 all are replaced
caseInsensitive bool Case insensitivity flag
리턴 string

Replicate() 공개 정적인 메소드

Replicates a character n number of times and returns a string
public static Replicate ( char character, int charCount ) : string
character char
charCount int
리턴 string

Replicate() 공개 정적인 메소드

Replicates an input string n number of times
public static Replicate ( string input, int charCount ) : string
input string
charCount int
리턴 string

SetProperty() 공개 정적인 메소드

public static SetProperty ( string propertyString, string key, string value ) : string
propertyString string
key string
value string
리턴 string

SetUrlEncodedKey() 공개 정적인 메소드

Allows setting of a value in a UrlEncoded string. If the key doesn't exist a new one is set, if it exists it's replaced with the new value.
public static SetUrlEncodedKey ( string urlEncoded, string key, string value ) : string
urlEncoded string A UrlEncoded string of key value pairs
key string
value string
리턴 string

StringToBytes() 공개 정적인 메소드

Converts a string into bytes for storage in any byte[] types buffer or stream format (like MemoryStream).
public static StringToBytes ( string text, Encoding encoding = null ) : byte[]
text string
encoding System.Text.Encoding The character encoding to use. Defaults to Unicode
리턴 byte[]

StringToStream() 공개 정적인 메소드

Creates a Stream from a string. Internally creates a memory stream and returns that.
public static StringToStream ( string text, Encoding encoding = null ) : Stream
text string
encoding System.Text.Encoding
리턴 Stream

StripNonNumber() 공개 정적인 메소드

Strips all non digit values from a string and only returns the numeric string.
public static StripNonNumber ( string input ) : string
input string
리턴 string

TerminateString() 공개 정적인 메소드

Terminates a string with the given end string/character, but only if the value specified doesn't already exist and the string is not empty.
public static TerminateString ( string value, string terminator ) : string
value string String to terminate
terminator string String to terminate the value string with
리턴 string

TextAbstract() 공개 정적인 메소드

Returns an abstract of the provided text by returning up to Length characters of a text string. If the text is truncated a ... is appended.
public static TextAbstract ( string text, int length ) : string
text string Text to abstract
length int Number of characters to abstract to
리턴 string

ToCamelCase() 공개 정적인 메소드

Takes a phrase and turns it into CamelCase text. White Space, punctuation and separators are stripped
public static ToCamelCase ( string phrase ) : string
phrase string Text to convert to CamelCase
리턴 string

TrimStart() 공개 정적인 메소드

Trims a sub string from a string
public static TrimStart ( string text, string textToTrim, bool caseInsensitive ) : string
text string
textToTrim string
caseInsensitive bool
리턴 string

TrimTo() 공개 정적인 메소드

Trims a string to a specific number of max characters
public static TrimTo ( string value, int charCount ) : string
value string
charCount int
리턴 string

UrlDecode() 공개 정적인 메소드

UrlDecodes a string without requiring System.Web
public static UrlDecode ( string text ) : string
text string String to decode.
리턴 string

UrlEncode() 공개 정적인 메소드

UrlEncodes a string without the requirement for System.Web
public static UrlEncode ( string text ) : string
text string
리턴 string

UrlEncodePathSafe() 공개 정적인 메소드

Encodes a few additional characters for use in paths Encodes: . #
public static UrlEncodePathSafe ( string text ) : string
text string
리턴 string