现在的位置: 首页 > 综合 > 正文

System.String

2014年01月18日 ⁄ 综合 ⁄ 共 22805字 ⁄ 字号 评论关闭
// ==++==
//
//
// Copyright (c) 2002 Microsoft Corporation. All rights reserved.
//
// The use and distribution terms for this software are contained in the file
// named license.txt, which can be found in the root of this distribution.
// By using this software in any fashion, you are agreeing to be bound by the
// terms of this license.
//
// You must not remove this notice, or any other, from this software.
//
//
// ==--==
/*============================================================
**
** Class: String
**
**
**
** Purpose: Contains headers for the String class. Actual implementations
** are in String.cpp
**
** Date: March 15, 1998
**
===========================================================*/
namespace System {
using System.Text;
using System;
using System.Globalization;
using System.Threading;
using System.Collections;
using System.Runtime.CompilerServices;
using va_list = System.ArgIterator;
using __UnmanagedMemoryStream = System.IO.__UnmanagedMemoryStream;
//
// For Information on these methods, please see COMString.cpp
//
// The String class represents a static string of characters. Many of
// the String methods perform some type of transformation on the current
// instance and return the result as a new String. All comparison methods are
// implemented as a part of String. As with arrays, character positions
// (indices) are zero-based.
//
// When passing a null string into a constructor in VJ and VC, the null should be
// explicitly type cast to a String.
// For Example:
// String s = new String((String)null);
// Text.Out.WriteLine(s);
//
/// <include file='doc/String.uex' path='docs/doc[@for="String"]/*' />
[Serializable] public sealed class String : IComparable, ICloneable, IConvertible, IEnumerable {

//
//NOTE NOTE NOTE NOTE
//These fields map directly onto the fields in an EE StringObject. See object.h for the layout.
//
[NonSerialized]private int m_arrayLength;
[NonSerialized]private int m_stringLength;
[NonSerialized]private char m_firstChar;

//private static readonly char FmtMsgMarkerChar='%';
//private static readonly char FmtMsgFmtCodeChar='!';
//These are defined in Com99/src/vm/COMStringCommon.h and must be kept in sync.
private const int TrimHead = 0;
private const int TrimTail = 1;
private const int TrimBoth = 2;

// The Empty constant holds the empty string value.
//We need to call the String constructor so that the compiler doesn't mark this as a literal.
//Marking this as a literal would mean that it doesn't show up as a field which we can access
//from native.
/// <include file='doc/String.uex' path='docs/doc[@for="String.Empty"]/*' />
public static readonly String Empty = "";

//
//Native Static Methods
//

// Joins an array of strings together as one string with a separator between each original string.
//
/// <include file='doc/String.uex' path='docs/doc[@for="String.Join"]/*' />
public static String Join (String separator, String[] value) {
if (value==null) {
throw new ArgumentNullException("value");
}
return Join(separator, value, 0, value.Length);
}

// Joins an array of strings together as one string with a separator between each original string.
//
/// <include file='doc/String.uex' path='docs/doc[@for="String.Join1"]/*' />
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern String Join (String separator, String[] value, int startIndex, int count);

[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern int nativeCompareOrdinal(String strA, String strB, bool bIgnoreCase);

[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern int nativeCompareOrdinalEx(String strA, int indexA, String strB, int indexB, int count);
//This will not work in case-insensitive mode for any character greater than 0x80.
//We'll throw an ArgumentException.
[MethodImplAttribute(MethodImplOptions.InternalCall)]
unsafe internal static extern int nativeCompareOrdinalWC(String strA, char *strBChars, bool bIgnoreCase, out bool success);


//
// This is a helper method for the security team. They need to uppercase some strings (guaranteed to be less
// than 0x80) before security is fully initialized. Without security initialized, we can't grab resources (the nlp's)
// from the assembly. This provides a workaround for that problem and should NOT be used anywhere else.
//
internal static String SmallCharToUpper(String strA) {
String newString = FastAllocateString(strA.Length);
nativeSmallCharToUpper(strA, newString);
return newString;
}

[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern void nativeSmallCharToUpper(String strIn, String strOut);

// This is a helper method for the security team. They need to construct strings from a char[]
// within their homebrew XML parser. They guarantee that the char[] they pass in isn't null and
// that the provided indices are valid so we just stuff real fast.
internal static String CreateFromCharArray( char[] array, int start, int count )
{
String newString = FastAllocateString( count );
FillStringArray( newString, 0, array, start, count );
return newString;
}

//
//
// NATIVE INSTANCE METHODS
//
//

//
// Search/Query methods
//

// Determines whether two strings match.
/// <include file='doc/String.uex' path='docs/doc[@for="String.Equals"]/*' />
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public extern override bool Equals(Object obj);

// Determines whether two strings match.
/// <include file='doc/String.uex' path='docs/doc[@for="String.Equals1"]/*' />
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public extern bool Equals(String value);

// Determines whether two Strings match.
/// <include file='doc/String.uex' path='docs/doc[@for="String.Equals2"]/*' />
public static bool Equals(String a, String b) {
if ((Object)a==(Object)b) {
return true;
}

if ((Object)a==null || (Object)b==null) {
return false;
}

return a.Equals(b);
}

/// <include file='doc/String.uex' path='docs/doc[@for="String.operatorEQ"]/*' />
public static bool operator == (String a, String b) {
return String.Equals(a, b);
}

/// <include file='doc/String.uex' path='docs/doc[@for="String.operatorNE"]/*' />
public static bool operator != (String a, String b) {
return !String.Equals(a, b);
}

[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern char InternalGetChar(int index);

// Gets the character at a specified position.
//
/// <include file='doc/String.uex' path='docs/doc[@for="String.this"]/*' />
[System.Runtime.CompilerServices.IndexerName("Chars")]
public char this[int index] {
get { return InternalGetChar(index); }
}

// Converts a substring of this string to an array of characters. Copies the
// characters of this string beginning at position startIndex and ending at
// startIndex + length - 1 to the character array buffer, beginning
// at bufferStartIndex.
//
/// <include file='doc/String.uex' path='docs/doc[@for="String.CopyTo"]/*' />
public void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count)
{
if (destination == null)
throw new ArgumentNullException("destination");
if (count < 0)
throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NegativeCount"));
if (sourceIndex < 0)
throw new ArgumentOutOfRangeException("sourceIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
if (count > Length - sourceIndex)
throw new ArgumentOutOfRangeException("sourceIndex", Environment.GetResourceString("ArgumentOutOfRange_IndexCount"));
if (destinationIndex > destination.Length-count || destinationIndex < 0)
throw new ArgumentOutOfRangeException("destinationIndex", Environment.GetResourceString("ArgumentOutOfRange_IndexCount"));
InternalCopyTo(sourceIndex, destination, destinationIndex, count);
}

[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern void InternalCopyTo(int sourceIndex, char[] destination, int destinationIndex, int count);

[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern void CopyToByteArray(int sourceIndex, byte[] destination, int destinationIndex, int charCount);

// Returns the entire string as an array of characters.
/// <include file='doc/String.uex' path='docs/doc[@for="String.ToCharArray"]/*' />
public char[] ToCharArray() {
return ToCharArray(0,Length);
}

// Returns a substring of this string as an array of characters.
//
/// <include file='doc/String.uex' path='docs/doc[@for="String.ToCharArray1"]/*' />
public char[] ToCharArray(int startIndex, int length)
{
// Range check everything.
if (startIndex < 0 || startIndex > Length || startIndex > Length - length)
throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
if (length < 0)
throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_Index"));

char[] chars = new char[length];
InternalCopyTo(startIndex, chars, 0, length);
return chars;
}

// Gets a hash code for this string. If strings A and B are such that A.Equals(B), then
// they will return the same hash code.
/// <include file='doc/String.uex' path='docs/doc[@for="String.GetHashCode"]/*' />
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public extern override int GetHashCode();

// Gets the length of this string
/// <include file='doc/String.uex' path='docs/doc[@for="String.Length"]/*' />
public int Length {
get { return InternalLength(); }
}

/// This is a EE implemented function so that the JIT can recognise is specially
/// and eliminate checks on character fetchs.
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private extern int InternalLength();

///<internalonly/>
internal int ArrayLength {
get { return (m_arrayLength); }
}

// Used by StringBuilder
internal int Capacity {
get { return (m_arrayLength - 1); }
}

// Creates an array of strings by splitting this string at each
// occurence of a separator. The separator is searched for, and if found,
// the substring preceding the occurence is stored as the first element in
// the array of strings. We then continue in this manner by searching
// the substring that follows the occurence. On the other hand, if the separator
// is not found, the array of strings will contain this instance as its only element.
// If the separator is null
// whitespace (i.e., Character.IsWhitespace) is used as the separator.
//
/// <include file='doc/String.uex' path='docs/doc[@for="String.Split"]/*' />
public String [] Split(params char [] separator) {
return Split(separator, Int32.MaxValue);
}

// Creates an array of strings by splitting this string at each
// occurence of a separator. The separator is searched for, and if found,
// the substring preceding the occurence is stored as the first element in
// the array of strings. We then continue in this manner by searching
// the substring that follows the occurence. On the other hand, if the separator
// is not found, the array of strings will contain this instance as its only element.
// If the spearator is the empty string (i.e., String.Empty), then
// whitespace (i.e., Character.IsWhitespace) is used as the separator.
// If there are more than count different strings, the last n-(count-1)
// elements are concatenated and added as the last String.
//
/// <include file='doc/String.uex' path='docs/doc[@for="String.Split1"]/*' />
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public extern String[] Split(char[] separator, int count);


// Returns a substring of this string.
//
/// <include file='doc/String.uex' path='docs/doc[@for="String.Substring"]/*' />
public String Substring (int startIndex) {
return this.Substring (startIndex, Length-startIndex);
}

// Returns a substring of this string.
//
/// <include file='doc/String.uex' path='docs/doc[@for="String.Substring1"]/*' />
public String Substring (int startIndex, int length) {

int thisLength = Length;

//Bounds Checking.
if (startIndex<0) {
throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_StartIndex"));
}

if (length<0) {
throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_NegativeLength"));
}

if (startIndex > thisLength-length) {
throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_IndexLength"));
}

String s = FastAllocateString(length);
FillSubstring(s, 0, this, startIndex, length);

return s;
}

[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern String TrimHelper(char[] trimChars, int trimType);

//This should really live on System.Globalization.CharacterInfo. However,
//Trim gets called by security while resgen is running, so we can't run
//CharacterInfo's class initializer (which goes to native and looks for a
//resource table that hasn't yet been attached to the assembly when resgen
//runs.
internal static readonly char[] WhitespaceChars =
{ (char) 0x9, (char) 0xA, (char) 0xB, (char) 0xC, (char) 0xD, (char) 0x20, (char) 0xA0,
(char) 0x2000, (char) 0x2001, (char) 0x2002, (char) 0x2003, (char) 0x2004, (char) 0x2005,
(char) 0x2006, (char) 0x2007, (char) 0x2008, (char) 0x2009, (char) 0x200A, (char) 0x200B,
(char) 0x3000, (char) 0xFEFF };

// Removes a string of characters from the ends of this string.
/// <include file='doc/String.uex' path='docs/doc[@for="String.Trim"]/*' />
public String Trim(params char[] trimChars) {
if (null==trimChars || trimChars.Length == 0) {
trimChars=WhitespaceChars;
}
return TrimHelper(trimChars,TrimBoth);
}

// Removes a string of characters from the beginning of this string.
/// <include file='doc/String.uex' path='docs/doc[@for="String.TrimStart"]/*' />
public String TrimStart(params char[] trimChars) {
if (null==trimChars || trimChars.Length == 0) {
trimChars=WhitespaceChars;
}
return TrimHelper(trimChars,TrimHead);
}


// Removes a string of characters from the end of this string.
/// <include file='doc/String.uex' path='docs/doc[@for="String.TrimEnd"]/*' />
public String TrimEnd(params char[] trimChars) {
if (null==trimChars || trimChars.Length == 0) {
trimChars=WhitespaceChars;
}
return TrimHelper(trimChars,TrimTail);
}


// Creates a new string with the characters copied in from ptr. If
// ptr is null, a string initialized to ";<;No Object>;"; (i.e.,
// String.NullString) is created.
//
// Issue: This method is only accessible from VC.
/// <include file='doc/String.uex' path='docs/doc[@for="String.String"]/*' />
[CLSCompliant(false), MethodImplAttribute(MethodImplOptions.InternalCall)]
unsafe public extern String(char *value);
/// <include file='doc/String.uex' path='docs/doc[@for="String.String1"]/*' />
[CLSCompliant(false), MethodImplAttribute(MethodImplOptions.InternalCall)]
unsafe public extern String(char *value, int startIndex, int length);

/// <include file='doc/String.uex' path='docs/doc[@for="String.String2"]/*' />
[CLSCompliant(false), MethodImplAttribute(MethodImplOptions.InternalCall)]
unsafe public extern String(sbyte *value);
/// <include file='doc/String.uex' path='docs/doc[@for="String.String3"]/*' />
[CLSCompliant(false), MethodImplAttribute(MethodImplOptions.InternalCall)]
unsafe public extern String(sbyte *value, int startIndex, int length);

/// <include file='doc/String.uex' path='docs/doc[@for="String.String4"]/*' />
[CLSCompliant(false), MethodImplAttribute(MethodImplOptions.InternalCall)]
unsafe public extern String(sbyte *value, int startIndex, int length, Encoding enc);

unsafe static private String CreateString(sbyte *value, int startIndex, int length, Encoding enc) {
if (enc == null)
return new String(value, startIndex, length); // default to ANSI
if (length < 0)
throw new ArgumentOutOfRangeException("length",Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
byte [] b = new byte[length];
__UnmanagedMemoryStream.memcpy((byte*)value, startIndex, b, 0, length);
return enc.GetString(b);
}

// For ASCIIEncoding::GetString()
unsafe static internal String CreateStringFromASCII(byte[] bytes, int startIndex, int length) {
BCLDebug.Assert(bytes != null, "need a byte[].");
BCLDebug.Assert(startIndex >= 0 && (startIndex < bytes.Length || bytes.Length == 0), "startIndex >= 0 && startIndex < bytes.Length");
BCLDebug.Assert(length >= 0 && length <= bytes.Length - startIndex, "length >= 0 && length <= bytes.Length - startIndex");
if (length == 0)
return String.Empty;
String s = FastAllocateString(length);
fixed(char* pChars = &s.m_firstChar) {
for(int i=0; i<length; i++)
pChars[i] = (char) (bytes[i+startIndex] & 0x7f);
}
return s;
}

[MethodImplAttribute(MethodImplOptions.InternalCall)]
private extern static String FastAllocateString(int length);

[MethodImplAttribute(MethodImplOptions.InternalCall)]
private extern static void FillString(String dest, int destPos, String src);

[MethodImplAttribute(MethodImplOptions.InternalCall)]
private extern static void FillStringChecked(String dest, int destPos, String src);

[MethodImplAttribute(MethodImplOptions.InternalCall)]
private extern static void FillStringEx(String dest, int destPos, String src,int srcLength);

[MethodImplAttribute(MethodImplOptions.InternalCall)]
private extern static void FillStringArray(String dest, int stringStart, char[] array, int charStart, int count);

[MethodImplAttribute(MethodImplOptions.InternalCall)]
private extern static void FillSubstring(String dest, int destPos, String src, int startPos, int count);



// Creates a new string from the characters in a subarray. The new string will
// be created from the characters in value between startIndex and
// startIndex + length - 1.
//
/// <include file='doc/String.uex' path='docs/doc[@for="String.String7"]/*' />
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public extern String(char [] value, int startIndex, int length);

// Creates a new string from the characters in a subarray. The new string will be
// created from the characters in value.
//
/// <include file='doc/String.uex' path='docs/doc[@for="String.String5"]/*' />
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public extern String(char [] value);

/// <include file='doc/String.uex' path='docs/doc[@for="String.String6"]/*' />
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public extern String(char c, int count);


//
//
// INSTANCE METHODS
//
//

// Provides a culture-correct string comparison. StrA is compared to StrB
// to determine whether it is lexicographically less, equal, or greater, and then returns
// either a negative integer, 0, or a positive integer; respectively.
//
/// <include file='doc/String.uex' path='docs/doc[@for="String.Compare"]/*' />
public static int Compare(String strA, String strB) {
return CultureInfo.CurrentCulture.CompareInfo.Compare(strA, strB, CompareOptions.None);
}

// Provides a culture-correct string comparison. strA is compared to strB
// to determine whether it is lexicographically less, equal, or greater, and then a
// negative integer, 0, or a positive integer is returned; respectively.
// The case-sensitive option is set by ignoreCase
//
/// <include file='doc/String.uex' path='docs/doc[@for="String.Compare1"]/*' />
public static int Compare(String strA, String strB, bool ignoreCase) {
if (ignoreCase) {
return CultureInfo.CurrentCulture.CompareInfo.Compare(strA, strB, CompareOptions.IgnoreCase);
}
return CultureInfo.CurrentCulture.CompareInfo.Compare(strA, strB, CompareOptions.None);
}

// Provides a culture-correct string comparison. strA is compared to strB
// to determine whether it is lexicographically less, equal, or greater, and then a
// negative integer, 0, or a positive integer is returned; respectively.
// The case-sensitive option is set by ignoreCase, and the culture is set
// by culture
//
/// <include file='doc/String.uex' path='docs/doc[@for="String.Compare2"]/*' />
public static int Compare(String strA, String strB, bool ignoreCase, CultureInfo culture) {
if (culture==null) {
throw new ArgumentNullException("culture");
}

if (ignoreCase) {
return culture.CompareInfo.Compare(strA, strB, CompareOptions.IgnoreCase);
}
return culture.CompareInfo.Compare(strA, strB, CompareOptions.None);
}

// Determines whether two string regions match. The substring of strA beginning
// at indexA of length count is compared with the substring of strB
// beginning at indexB of the same length.
//
/// <include file='doc/String.uex' path='docs/doc[@for="String.Compare3"]/*' />
public static int Compare(String strA, int indexA, String strB, int indexB, int length) {
int lengthA = length;
int lengthB = length;

if (strA!=null) {
if (strA.Length - indexA < lengthA) {
lengthA = (strA.Length - indexA);
}
}

if (strB!=null) {
if (strB.Length - indexB < lengthB) {
lengthB = (strB.Length - indexB);
}
}
return CultureInfo.CurrentCulture.CompareInfo.Compare(strA, indexA, lengthA, strB, indexB, lengthB, CompareOptions.None);
}


// Determines whether two string regions match. The substring of strA beginning
// at indexA of length count is compared with the substring of strB
// beginning at indexB of the same length. Case sensitivity is determined by the ignoreCase boolean.
//
/// <include file='doc/String.uex' path='docs/doc[@for="String.Compare4"]/*' />
public static int Compare(String strA, int indexA, String strB, int indexB, int length, bool ignoreCase) {
int lengthA = length;
int lengthB = length;

if (strA!=null) {
if (strA.Length - indexA < lengthA) {
lengthA = (strA.Length - indexA);
}
}

if (strB!=null) {
if (strB.Length - indexB < lengthB) {
lengthB = (strB.Length - indexB);
}
}

if (ignoreCase) {
return CultureInfo.CurrentCulture.CompareInfo.Compare(strA, indexA, lengthA, strB, indexB, lengthB, CompareOptions.IgnoreCase);
}
return CultureInfo.CurrentCulture.CompareInfo.Compare(strA, indexA, lengthA, strB, indexB, lengthB, CompareOptions.None);
}

// Determines whether two string regions match. The substring of strA beginning
// at indexA of length length is compared with the substring of strB
// beginning at indexB of the same length. Case sensitivity is determined by the ignoreCase boolean,
// and the culture is set by culture.
//
/// <include file='doc/String.uex' path='docs/doc[@for="String.Compare5"]/*' />
public static int Compare(String strA, int indexA, String strB, int indexB, int length, bool ignoreCase, CultureInfo culture) {
if (culture==null) {
throw new ArgumentNullException("culture");
}

int lengthA = length;
int lengthB = length;

if (strA!=null) {
if (strA.Length - indexA < lengthA) {
lengthA = (strA.Length - indexA);
}
}

if (strB!=null) {
if (strB.Length - indexB < lengthB) {
lengthB = (strB.Length - indexB);
}
}

if (ignoreCase) {
return culture.CompareInfo.Compare(strA,indexA,lengthA, strB, indexB, lengthB,CompareOptions.IgnoreCase);
} else {
return culture.CompareInfo.Compare(strA,indexA,lengthA, strB, indexB, lengthB,CompareOptions.None);
}
}

// Compares this object to another object, returning an integer that
// indicates the relationship. This method returns a value less than 0 if this is less than value, 0
// if this is equal to value, or a value greater than 0
// if this is greater than value. Strings are considered to be
// greater than all non-String objects. Note that this means sorted
// arrays would contain nulls, other objects, then Strings in that order.
//
/// <include file='doc/String.uex' path='docs/doc[@for="String.CompareTo"]/*' />
public int CompareTo(Object value) {
if (value == null) {
return 1;
}

if (!(value is String)) {
throw new ArgumentException(Environment.GetResourceString("Arg_MustBeString"));
}

return String.Compare(this,(String)value);
}

// Determines the sorting relation of StrB to the current instance.
//
/// <include file='doc/String.uex' path='docs/doc[@for="String.CompareTo1"]/*' />
public int CompareTo(String strB) {
if (strB==null) {
return 1;
}
return CultureInfo.CurrentCulture.CompareInfo.Compare(this, strB, 0);
}

// Compares strA and strB using an ordinal (code-point) comparison.
//
/// <include file='doc/String.uex' path='docs/doc[@for="String.CompareOrdinal"]/*' />
public static int CompareOrdinal(String strA, String strB) {
if (strA == null || strB == null) {
if ((Object)strA==(Object)strB) { //they're both null;
return 0;
}
return (strA==null)? -1 : 1; //-1 if A is null, 1 if B is null.
}

return nativeCompareOrdinal(strA, strB, false);
}

// Compares strA and strB using an ordinal (code-point) comparison.
//
/// <include file='doc/String.uex' path='docs/doc[@for="String.CompareOrdinal1"]/*' />
public static int CompareOrdinal(String strA, int indexA, String strB, int indexB, int length) {
if (strA == null || strB == null) {
if ((Object)strA==(Object)strB) { //they're both null;
return 0;
}

return (strA==null)? -1 : 1; //-1 if A is null, 1 if B is null.
}

return nativeCompareOrdinalEx(strA, indexA, strB, indexB, length);
}


// Determines whether a specified string is a suffix of the the current instance.
//
// The case-sensitive and culture-sensitive option is set by options,
// and the default culture is used.
//
/// <include file='doc/String.uex' path='docs/doc[@for="String.EndsWith"]/*' />
public bool EndsWith(String value) {
if (null==value) {
throw new ArgumentNullException("value");
}
int valueLen = value.Length;
int thisLen = this.Length;
if (valueLen>thisLen) {
return false;
}
return (0==Compare(this, thisLen-valueLen, value, 0, valueLen));
}

internal bool EndsWith(char value) {
int thisLen = this.Length;
if (thisLen != 0) {
if (this[thisLen - 1] == value)
return true;
}
return false;
}


// Returns the index of the first occurance of value in the current instance.
// The search starts at startIndex and runs thorough the next count characters.
//
/// <include file='doc/String.uex' path='docs/doc[@for="String.IndexOf"]/*' />
public int IndexOf(char value) {
return IndexOf(value, 0, this.Length);
}

/// <include file='doc/String.uex' path='docs/doc[@for="String.IndexOf1"]/*' />
public int IndexOf(char value, int startIndex) {
return IndexOf(value, startIndex, this.Length - startIndex);
}

/// <include file='doc/String.uex' path='docs/doc[@for="String.IndexOf2"]/*' />
[MethodImplAttribut

抱歉!评论已关闭.