예제 #1
0
        public unsafe int LastIndexOf(char value, int startIndex, int count)
        {
            if (Length == 0)
            {
                return(-1);
            }

            if ((uint)startIndex >= (uint)Length)
            {
                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLess);
            }

            if ((uint)count > (uint)startIndex + 1)
            {
                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count);
            }

            int startSearchAt = startIndex + 1 - count;
            int result        = SpanHelpers.LastIndexOfValueType(ref Unsafe.As <char, short>(ref Unsafe.Add(ref _firstChar, startSearchAt)), (short)value, count);

            return(result < 0 ? result : result + startSearchAt);
        }
예제 #2
0
 // Returns the index of the last occurrence of a specified character in the current instance.
 // The search starts at startIndex and runs backwards to startIndex - count + 1.
 // The character at position startIndex is included in the search.  startIndex is the larger
 // index within the string.
 public int LastIndexOf(char value)
 => SpanHelpers.LastIndexOfValueType(ref Unsafe.As <char, short>(ref _firstChar), (short)value, Length);