System.Globalization.CompareInfo.LastIndexOf C# (CSharp) Méthode

LastIndexOf() public méthode

public LastIndexOf ( String source, String value, int startIndex, int count, CompareOptions options ) : int
source String
value String
startIndex int
count int
options CompareOptions
Résultat int
        public unsafe virtual int LastIndexOf(String source, String value, int startIndex, int count, CompareOptions options) 
        {
            // Verify Arguments
            if (source == null)
                throw new ArgumentNullException("source");
            if (value == null)
                throw new ArgumentNullException("value");

            // Validate CompareOptions
            // Ordinal can't be selected with other flags
            if ((options & ValidIndexMaskOffFlags) != 0 && 
                (options != CompareOptions.Ordinal) && 
                (options != CompareOptions.OrdinalIgnoreCase))
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), "options"); 

            // Special case for 0 length input strings
            if (source.Length == 0 && (startIndex == -1 || startIndex == 0))
                return (value.Length == 0) ? 0 : -1;

            // Make sure we're not out of range
            if (startIndex < 0 || startIndex > source.Length)
                throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));

            // Make sure that we allow startIndex == source.Length
            if (startIndex == source.Length)
            {
                startIndex--;
                if (count > 0)
                    count--;

                // If we are looking for nothing, just return 0
                if (value.Length == 0 && count >= 0 && startIndex - count + 1 >= 0)
                    return startIndex;
            }

            // 2nd have of this also catches when startIndex == MAXINT, so MAXINT - 0 + 1 == -1, which is < 0.
            if (count < 0 || startIndex - count + 1 < 0)
                throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count"));

            if (options == CompareOptions.OrdinalIgnoreCase)
            {
                return TextInfo.LastIndexOfStringOrdinalIgnoreCase(source, value, startIndex, count);
            }


            return (LastIndexOfString(m_pSortingTable, this.m_sortingLCID, source, value, startIndex, count, (int)options));
        }
    

Same methods

CompareInfo::LastIndexOf ( String source, String value ) : int
CompareInfo::LastIndexOf ( String source, String value, CompareOptions options ) : int
CompareInfo::LastIndexOf ( String source, String value, int startIndex ) : int
CompareInfo::LastIndexOf ( String source, String value, int startIndex, CompareOptions options ) : int
CompareInfo::LastIndexOf ( String source, String value, int startIndex, int count ) : int
CompareInfo::LastIndexOf ( String source, char value ) : int
CompareInfo::LastIndexOf ( String source, char value, CompareOptions options ) : int
CompareInfo::LastIndexOf ( String source, char value, int startIndex ) : int
CompareInfo::LastIndexOf ( String source, char value, int startIndex, CompareOptions options ) : int
CompareInfo::LastIndexOf ( String source, char value, int startIndex, int count ) : int
CompareInfo::LastIndexOf ( String source, char value, int startIndex, int count, CompareOptions options ) : int

Usage Example

Exemple #1
0
	void AssertLastIndexOf (string message, int expected, string source,
		string target, int idx, int len, CompareOptions opt, CompareInfo ci)
	{
		Assert.AreEqual (expected, ci.LastIndexOf (source, target, idx, len, opt), message);
	}
All Usage Examples Of System.Globalization.CompareInfo::LastIndexOf