System.Globalization.CompareInfo.LastIndexOf C# (CSharp) Method

LastIndexOf() public method

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

            // 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 -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--;
            }
            
            // 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.nativeLastIndexOfCharOrdinalIgnoreCase(
                            TextInfo.InvariantNativeTextInfo, 
                            source, 
                            value, 
                            startIndex, 
                            count);
            }


            return (LastIndexOfChar(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, String value, int startIndex, int count, CompareOptions options ) : 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

Usage Example

Example #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