当前位置: 首页>>代码示例>>C#>>正文


C# StringSegment.IndexOf方法代码示例

本文整理汇总了C#中StringSegment.IndexOf方法的典型用法代码示例。如果您正苦于以下问题:C# StringSegment.IndexOf方法的具体用法?C# StringSegment.IndexOf怎么用?C# StringSegment.IndexOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StringSegment的用法示例。


在下文中一共展示了StringSegment.IndexOf方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: StringSegment_IndexOfString_ReturnsNegativeOneForNonExistingCharacter

        public void StringSegment_IndexOfString_ReturnsNegativeOneForNonExistingCharacter()
        {
            var segment = new StringSegment("Hello, world!");
            var result = segment.IndexOf("zorld");

            TheResultingValue(result).ShouldBe(-1);
        }
开发者ID:prshreshtha,项目名称:ultraviolet,代码行数:7,代码来源:StringSegmentTest.cs

示例2: StringSegment_IndexOfString_ReturnsCorrectValueForExistingCharacter

        public void StringSegment_IndexOfString_ReturnsCorrectValueForExistingCharacter()
        {
            var segment = new StringSegment("Hello, world!");
            var result = segment.IndexOf("world");

            TheResultingValue(result).ShouldBe(7);
        }
开发者ID:prshreshtha,项目名称:ultraviolet,代码行数:7,代码来源:StringSegmentTest.cs

示例3: HandleTextEntryValidation

        /// <summary>
        /// Handles text entry validation for the updown's text editor.
        /// </summary>
        private static void HandleTextEntryValidation(DependencyObject element, StringSegment text, Int32 offset, Char character, ref Boolean valid, ref RoutedEventData data)
        {
            var numericUpDown = (NumericUpDown)element;
            if (numericUpDown.PART_Input != data.OriginalSource)
                return;

            data.Handled = true;

            // Negative sign must be inserted at the beginning of the text.
            // Negative sign is only allowed if Minimum is less than zero.
            if (character == '-')
            {
                if (offset > 0 || numericUpDown.Minimum >= 0)
                    valid = false;

                return;
            }

            // Nothing can be inserted before the negative sign, if there is one.
            var negativeSignPos = text.IndexOf('-');
            if (negativeSignPos >= 0 && offset < 1)
            {
                valid = false;
                return;
            }
            
            // Decimal separator can only be inserted if we allow decimal points.
            // Decimal separator can only be inserted if it doesn't introduce more than the allowed number of decimals.
            var decimalSeparatorPos = text.IndexOf('.');
            if (character == '.')
            {
                if (decimalSeparatorPos >= 0 || numericUpDown.DecimalPlaces == 0)
                {
                    valid = false;
                    return;
                }

                var decimalsIntroduced = text.Length - offset;
                if (decimalsIntroduced > numericUpDown.DecimalPlaces)
                    valid = false;

                return;
            }

            // Non-digit characters cannot be inserted.
            if (!Char.IsDigit(character))
            {
                valid = false;
                return;
            }

            // Post-decimal digits can only be inserted if we have fewer than DecimalPlaces digits there already.
            var decimalCount = (decimalSeparatorPos < 0) ? 0 : text.Length - (decimalSeparatorPos + 1);
            if (decimalSeparatorPos >= 0 && decimalSeparatorPos < offset && decimalCount >= numericUpDown.DecimalPlaces)
            {
                valid = false;
                return;
            }
        }
开发者ID:prshreshtha,项目名称:ultraviolet,代码行数:62,代码来源:NumericUpDown.cs

示例4: IndexOf_SearchOnlyInsideTheRange_IfStartAndCountAreProvided

        public void IndexOf_SearchOnlyInsideTheRange_IfStartAndCountAreProvided()
        {
            // Arrange
            const string buffer = "Hello, World!, Hello people!";
            var segment = new StringSegment(buffer, 3, buffer.Length - 3);

            // Act
            var result = segment.IndexOf('!', 15, 5);

            // Assert
            Assert.Equal(-1, result);
        }
开发者ID:leloulight,项目名称:Common,代码行数:12,代码来源:StringSegmentTest.cs

示例5: IndexOf_SkipsANumberOfCaracters_IfStartIsProvided

        public void IndexOf_SkipsANumberOfCaracters_IfStartIsProvided()
        {
            // Arrange
            const string buffer = "Hello, World!, Hello people!";
            var segment = new StringSegment(buffer, 3, buffer.Length - 3);

            // Act
            var result = segment.IndexOf('!', 15);

            // Assert
            Assert.Equal(buffer.Length - 4, result);
        }
开发者ID:leloulight,项目名称:Common,代码行数:12,代码来源:StringSegmentTest.cs

示例6: IndexOf_ReturnsMinusOne_IfElementNotInSegment

        public void IndexOf_ReturnsMinusOne_IfElementNotInSegment()
        {
            // Arrange
            var segment = new StringSegment("Hello, World!", 1, 3);

            // Act
            var result = segment.IndexOf(',');

            // Assert
            Assert.Equal(-1, result);
        }
开发者ID:leloulight,项目名称:Common,代码行数:11,代码来源:StringSegmentTest.cs

示例7: IndexOf_ComputesIndex_RelativeToTheCurrentSegment

        public void IndexOf_ComputesIndex_RelativeToTheCurrentSegment()
        {
            // Arrange
            var segment = new StringSegment("Hello, World!", 1, 10);

            // Act
            var result = segment.IndexOf(',');

            // Assert
            Assert.Equal(4, result);
        }
开发者ID:leloulight,项目名称:Common,代码行数:11,代码来源:StringSegmentTest.cs

示例8: IndexOf

 public void IndexOf(string content, string search, int expected)
 {
     var segment = new StringSegment(content);
     Assert.Equal(expected, segment.IndexOf(search));
 }
开发者ID:DM-TOR,项目名称:nhin-d,代码行数:5,代码来源:StringSegmentFacts.cs


注:本文中的StringSegment.IndexOf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。