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


C# StringBuilder.Contains方法代码示例

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


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

示例1: Test_CollectionFromSystemStringBuilderAdapter

Test_CollectionFromSystemStringBuilderAdapter()
{
    Print( "Create" );
    var c =
        new StringBuilder( "abcde" )
        .AsHalfdecentCollection();

    Print( ".Stream()" );
    Assert(
        c.Stream()
        .SequenceEqual(
            Stream.Create( 'a', 'b', 'c', 'd', 'e' ) ) );

    Print( ".GetAndReplaceWhere( Predicate< char > )" );
    var to = new SCG.List< char >();
    Stream.Create( 'B' )
        .To( c.GetAndReplaceWhere( ch => ch == 'b' ) )
        .EmptyTo( to.AsSink() );
    Assert(
        c.Stream()
        .SequenceEqual(
            Stream.Create( 'a', 'B', 'c', 'd', 'e' ) ) );
    to.Sort();
    Assert(
        to.SequenceEqual(
            SystemEnumerable.Create( 'b' ) ) );

    Print( ".GetAndRemoveWhere( Predicate< char > )" );
    to.Clear();
    c.GetAndRemoveWhere( ch => ch == 'B' )
        .EmptyTo( to.AsSink() );
    Assert(
        c.Stream()
        .SequenceEqual(
            Stream.Create( 'a', 'c', 'd', 'e' ) ) );
    to.Sort();
    Assert(
        to.SequenceEqual(
            SystemEnumerable.Create( 'B' ) ) );

    Print( ".Get( IInteger )" );
    Assert( c.Get( 0 ) == 'a' );
    Assert( c.Get( 1 ) == 'c' );
    Assert( c.Get( 2 ) == 'd' );
    Assert( c.Get( 3 ) == 'e' );

    Print( ".Replace( IInteger, char )" );
    c.Replace( 1, 'C' );
    Assert(
        c.Stream()
        .SequenceEqual(
            Stream.Create( 'a', 'C', 'd', 'e' ) ) );

    Print( ".Remove( IInteger )" );
    c.Remove( 1 );
    Assert(
        c.Stream()
        .SequenceEqual(
            Stream.Create( 'a', 'd', 'e' ) ) );

    Print( ".Contains( IInteger )" );
    Assert( !c.Contains( -1 ) );
    Assert( c.Contains( 0 ) );
    Assert( c.Contains( 1 ) );
    Assert( c.Contains( 2 ) );
    Assert( !c.Contains( 3 ) );

    Print( ".Stream( IInteger )" );
    Assert(
        c.Stream( 1 )
        .SequenceEqual(
            Stream.Create( 'd' ) ) );

    Print( ".GetAndReplaceAll( IInteger )" );
    to.Clear();
    Stream.Create( 'D' )
        .To( c.GetAndReplaceAll( 1 ) )
        .EmptyTo( to.AsSink() );
    Assert(
        c.Stream()
        .SequenceEqual(
            Stream.Create( 'a', 'D', 'e' ) ) );
    Assert(
        to.SequenceEqual(
            SystemEnumerable.Create( 'd' ) ) );

    Print( ".GetAndRemoveAll( IInteger )" );
    to.Clear();
    c.GetAndRemoveAll( 1 )
        .EmptyTo( to.AsSink() );
    Assert(
        c.Stream()
        .SequenceEqual(
            Stream.Create( 'a', 'e' ) ) );
    Assert(
        to.SequenceEqual(
            SystemEnumerable.Create( 'D' ) ) );

    Print( ".Add( IInteger, char )" );
    c.Add( 1, 'b' );
//.........这里部分代码省略.........
开发者ID:macro187,项目名称:halfdecentsharp,代码行数:101,代码来源:Tests.cs

示例2: Contains__A_String_Builder_Contains_Text

 public void Contains__A_String_Builder_Contains_Text()
 {
     var stringBuilder = new StringBuilder("Do greatest at in learning steepest. Breakfast extremity suffering one who all otherwise suspected. He at no nothing forbade up moments. Wholly uneasy at missed be of pretty whence. John way sir high than law who week. Surrounded prosperous introduced it if is up dispatched. Improved so strictly produced answered elegance is.");
     var result = stringBuilder.Contains("prosperous introduced");
     Assert.IsTrue(result == true);
 }
开发者ID:ThoughtDrive,项目名称:XtensionMethods,代码行数:6,代码来源:StringBuilder.cs


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