本文整理汇总了C#中StringParser.Longest方法的典型用法代码示例。如果您正苦于以下问题:C# StringParser.Longest方法的具体用法?C# StringParser.Longest怎么用?C# StringParser.Longest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringParser
的用法示例。
在下文中一共展示了StringParser.Longest方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Should_choose_the_greediest_one
public void Should_choose_the_greediest_one()
{
string subject = "Hello, World";
var p = new StringParser();
Parser<string, string> first = from x in p.String("Hello")
select x;
Assert.IsTrue(first.ParseString(subject).HasValue, "First did not match");
Parser<string, string> second = from x in p.String("Hello")
from y in p.Char(',')
from ws in p.Whitespace()
from z in p.String("World")
select x + z;
Assert.IsTrue(second.ParseString(subject).HasValue, "Second did not match");
Parser<string, string> parser = p.Longest(first, second);
Result<string, string> result = parser.ParseString(subject);
Assert.IsTrue(result.HasValue, "Neither matched");
Assert.AreEqual("HelloWorld", result.Value, "Longest parser should have matched");
}
示例2: Should_skip_until_the_longest_is_found
public void Should_skip_until_the_longest_is_found()
{
string subject = "Hello World";
var p = new StringParser();
Parser<string, string> parser = from x in p.SkipUntil(p.Longest(p.String("Hello"), p.String("Hello World")))
select x;
var result = parser.ParseString(subject);
Assert.IsTrue(result.HasValue);
Assert.AreEqual("Hello World", result.Value);
}