本文整理汇总了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);
}
示例2: StringSegment_IndexOfString_ReturnsCorrectValueForExistingCharacter
public void StringSegment_IndexOfString_ReturnsCorrectValueForExistingCharacter()
{
var segment = new StringSegment("Hello, world!");
var result = segment.IndexOf("world");
TheResultingValue(result).ShouldBe(7);
}
示例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;
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例8: IndexOf
public void IndexOf(string content, string search, int expected)
{
var segment = new StringSegment(content);
Assert.Equal(expected, segment.IndexOf(search));
}