C# 클래스 Loyc.StringExt

Extension methods for strings, such as SplitAt, Left, Right, Format and Slice.
파일 보기 프로젝트 열기: qwertie/ecsharp

공개 메소드들

메소드 설명
EliminateNamedArgs ( string format ) : string

Called by Format to replace named placeholders with numeric placeholders in format strings.

Find ( this str, UString what, bool ignoreCase = false ) : UString
FormatCore ( this format ) : string

This formatter works like string.Format, except that named placeholders accepted as well as numeric placeholders. This method replaces named placeholders with numbers, then calls string.Format.

Named placeholders are useful for communicating information about a placeholder to a human translator. Here is an example: Not enough memory to {load/parse} '{filename}'. In some cases a translator might have difficulty translating a phrase without knowing what a numeric placeholder ({0} or {1}) refers to, so a named placeholder can provide an important clue. The localization system is invoked as follows: string msg = "{man's name} meets {woman's name}.".Localized( "man's name", mansName, "woman's name", womansName); The placeholder names are not case sensitive. You can use numeric placeholders, alignment and formatting codes also: string msg = "You need to run {dist,6:###.00} km to reach {0}".Localized( cityName, "dist", 2.9); It is assumed that the placeholder name ends at the first comma or colon; hence the placeholder in this example is called "dist", not "dist,6:###.00". Typically, the named arguments are expected to start at index N+1 in the variable argument array, where {N} is the largest numeric placeholder, and if there are no numeric placeholders then the named arguments should begin at index 0. In this example there is a {0}, so the named arguments should start at index 1. However, since named arguments always come in pairs, an extra rule increments the N if the number of remaining arguments starting at N is not an even number. For example, in string msg = "Hello {0}, you'll go to {school name} next year.".Localized( firstName, lastName, "school name", schoolName); There are three args left after the numeric ones, so the first remaining argument is ignored to make it an even number. If a placeholder name is not found in the argument list then it is not replaced with a number before the call to string.Format, so a FormatException will occur.

Join ( string separator, IEnumerable value ) : string

Converts a series of values to strings, and concatenates them with a given separator between them.

This method (but taking IEnumerable{T}) exists in the BCL starting in .NET 4

Join ( string separator, IEnumerator value ) : string
Left ( this s, int count ) : string

Returns the leftmost 'count' characters of 's', or s itself if count > s.Length.

Right ( this s, int count ) : string

Returns the rightmost 'count' characters of 's', or s itself if count > s.Length.

SafeSubstring ( this s, int startIndex, int length = int.MaxValue ) : string

A variation on String.Substring() that never throws.

This is best explained by examples: "Hi everybody!".SafeSubstring(8, 500) == "body!" "Hi everybody!".SafeSubstring(-3, 5) == "Hi" "Hi everybody!".SafeSubstring(-5, 5) == "" "Hi everybody!".SafeSubstring(8, -5) == "" "Hi everybody!".SafeSubstring(500, 8) == "" "Hi everybody!".SafeSubstring(int.MinValue + 500, int.MaxValue) == "Hi everybody!" ((string)null).SafeSubstring(0, 1) == null

Slice ( this str, int start, int count = int.MaxValue ) : UString
SplitAt ( this s, char delimiter ) : UString>.Pair

Gets the substrings to the left and right of a dividing character.

SplitAt ( this s, string delimiter ) : UString>.Pair
TryGet ( this s, int index, char defaultValue ) : char
TryGet ( this s, int index ) : char?

메소드 상세

EliminateNamedArgs() 공개 정적인 메소드

Called by Format to replace named placeholders with numeric placeholders in format strings.
public static EliminateNamedArgs ( string format ) : string
format string
리턴 string

Find() 공개 정적인 메소드

public static Find ( this str, UString what, bool ignoreCase = false ) : UString
str this
what UString
ignoreCase bool
리턴 UString

FormatCore() 공개 정적인 메소드

This formatter works like string.Format, except that named placeholders accepted as well as numeric placeholders. This method replaces named placeholders with numbers, then calls string.Format.
Named placeholders are useful for communicating information about a placeholder to a human translator. Here is an example: Not enough memory to {load/parse} '{filename}'. In some cases a translator might have difficulty translating a phrase without knowing what a numeric placeholder ({0} or {1}) refers to, so a named placeholder can provide an important clue. The localization system is invoked as follows: string msg = "{man's name} meets {woman's name}.".Localized( "man's name", mansName, "woman's name", womansName); The placeholder names are not case sensitive. You can use numeric placeholders, alignment and formatting codes also: string msg = "You need to run {dist,6:###.00} km to reach {0}".Localized( cityName, "dist", 2.9); It is assumed that the placeholder name ends at the first comma or colon; hence the placeholder in this example is called "dist", not "dist,6:###.00". Typically, the named arguments are expected to start at index N+1 in the variable argument array, where {N} is the largest numeric placeholder, and if there are no numeric placeholders then the named arguments should begin at index 0. In this example there is a {0}, so the named arguments should start at index 1. However, since named arguments always come in pairs, an extra rule increments the N if the number of remaining arguments starting at N is not an even number. For example, in string msg = "Hello {0}, you'll go to {school name} next year.".Localized( firstName, lastName, "school name", schoolName); There are three args left after the numeric ones, so the first remaining argument is ignored to make it an even number. If a placeholder name is not found in the argument list then it is not replaced with a number before the call to string.Format, so a FormatException will occur.
public static FormatCore ( this format ) : string
format this
리턴 string

Join() 공개 정적인 메소드

Converts a series of values to strings, and concatenates them with a given separator between them.
This method (but taking IEnumerable{T}) exists in the BCL starting in .NET 4
public static Join ( string separator, IEnumerable value ) : string
separator string
value IEnumerable
리턴 string

Join() 공개 정적인 메소드

public static Join ( string separator, IEnumerator value ) : string
separator string
value IEnumerator
리턴 string

Left() 공개 정적인 메소드

Returns the leftmost 'count' characters of 's', or s itself if count > s.Length.
public static Left ( this s, int count ) : string
s this
count int
리턴 string

Right() 공개 정적인 메소드

Returns the rightmost 'count' characters of 's', or s itself if count > s.Length.
public static Right ( this s, int count ) : string
s this
count int
리턴 string

SafeSubstring() 공개 정적인 메소드

A variation on String.Substring() that never throws.
This is best explained by examples: "Hi everybody!".SafeSubstring(8, 500) == "body!" "Hi everybody!".SafeSubstring(-3, 5) == "Hi" "Hi everybody!".SafeSubstring(-5, 5) == "" "Hi everybody!".SafeSubstring(8, -5) == "" "Hi everybody!".SafeSubstring(500, 8) == "" "Hi everybody!".SafeSubstring(int.MinValue + 500, int.MaxValue) == "Hi everybody!" ((string)null).SafeSubstring(0, 1) == null
public static SafeSubstring ( this s, int startIndex, int length = int.MaxValue ) : string
s this
startIndex int
length int
리턴 string

Slice() 공개 정적인 메소드

public static Slice ( this str, int start, int count = int.MaxValue ) : UString
str this
start int
count int
리턴 UString

SplitAt() 공개 정적인 메소드

Gets the substrings to the left and right of a dividing character.
public static SplitAt ( this s, char delimiter ) : UString>.Pair
s this String to split
delimiter char Dividing character.
리턴 UString>.Pair

SplitAt() 공개 정적인 메소드

public static SplitAt ( this s, string delimiter ) : UString>.Pair
s this
delimiter string
리턴 UString>.Pair

TryGet() 공개 정적인 메소드

public static TryGet ( this s, int index, char defaultValue ) : char
s this
index int
defaultValue char
리턴 char

TryGet() 공개 정적인 메소드

public static TryGet ( this s, int index ) : char?
s this
index int
리턴 char?