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


C# StringBuilder.Equals方法代码示例

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


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

示例1: TestEquals

    public static void TestEquals()
    {
        StringBuilder sb1 = new StringBuilder("Hello");
        StringBuilder sb2 = new StringBuilder("HelloX");

        bool b;
        b = sb1.Equals(sb1);
        Assert.True(b);
        b = sb1.Equals(sb2);
        Assert.False(b);
    }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:11,代码来源:StringBuilder.cs

示例2: runTest

 public virtual bool runTest()
   {
   Console.Error.WriteLine( "Co1454ctor_Strings.  runTest started." );
   int iCountErrors = 0;
   StringBuilder sbl2 = null;
   String str2b = null;
   String str2c = null;
   String str2d = null;
   String str2e = null;
   String str2_All = null;
   String str2_Some = null;
   String str9 = null;
   IntlStrings intl = new IntlStrings();
   str9 = intl.GetString(6, true, true);
   str2_All = str9;
   if ( ! str9.Equals( str2_All ) )
     {
     iCountErrors += 1;
     Console.Error.WriteLine(  "POINTTOBREAK:  Error E_6555im! (Co1454ctor_Strings)"  );
     }
   str2b = "Bb";
   str2c = "Cc";
   str2d = "Dd";
   str2e = "Ee";
   str2_All = "BbCcDdEe";
   str9 =  "BbCcDdEe" ;
   if ( ! str9.Equals( str2_All ) )
     {
     iCountErrors += 1;
     Console.Error.WriteLine(  "POINTTOBREAK:  Error E_638im! (Co1454ctor_Strings)"  );
     }
   sbl2 = new StringBuilder( "BbCcDd" );
   sbl2.Append( str2e );
   str9 = sbl2.ToString();
   if ( ! str9.Equals( str2_All ) )
     {
     iCountErrors += 1;
     Console.Error.WriteLine(  "POINTTOBREAK:  Error E_517cw! (Co1454ctor_Strings)"  );
     }
   str9 =  "Bb" + "Cc" +"Dd" ;
   str2_Some = "BbCcDd";
   if ( ! str9.Equals( str2_Some ) )
     {
     iCountErrors += 1;
     Console.Error.WriteLine(  "POINTTOBREAK:  Error E_460is! (Co1454ctor_Strings)"  );
     }
   str9 =  str2b + str2c + str2d ;
   str9 = new StringBuilder( str9 ).Append( str2e ).ToString();
   if ( ! str9.Equals( str2_All ) )
     {
     iCountErrors += 1;
     Console.Error.WriteLine(  "POINTTOBREAK:  Error E_253xi! (Co1454ctor_Strings)"  );
     }
   if ( iCountErrors == 0 ) {   return true; }
   else {  return false;}
   }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:56,代码来源:co1454ctor_strings.cs

示例3: Main

    public static void Main()
    {
        int count = int.Parse(Console.ReadLine());
        int[] numbers = Console.ReadLine().Trim().Split().Select(int.Parse).ToArray();
        bool haveMatch = false;

        StringBuilder left = new StringBuilder();
        StringBuilder right = new StringBuilder();

        for (int a = 0; a < count; a++)
        {
            for (int b = 0; b < count; b++)
            {
                for (int c = 0; c < count; c++)
                {
                    for (int d = 0; d < count; d++)
                    {
                        if (a != b && a != c && a != d && b != c && b != d && c != d)
                        {
                            left.Append(numbers[a]);
                            left.Append(numbers[b]);
                            right.Append(numbers[c]);
                            right.Append(numbers[d]);

                            if (left.Equals(right))
                            {
                                haveMatch = true;
                                Console.WriteLine("{0}|{1}=={2}|{3}", numbers[a], numbers[b], numbers[c], numbers[d]);
                            }

                            left.Clear();
                            right.Clear();
                        }
                    }
                }
            }
        }

        if (!haveMatch)
        {
            Console.WriteLine("No");
        }
    }
开发者ID:zhecho1215,项目名称:HomeWorks,代码行数:43,代码来源:StuckNumbers.cs

示例4: Evaluate

    static StringBuilder Evaluate(StringBuilder buffer, string tag = "")
    {
        // the method walks through "buffer" character by character
        // and prints any of them to the output in accordance to the type of surrounding pair of tags
        // if a pair of tags are found inside the buffer
        // the method calls itself with the text inside those tags (using recursion)
        // then the result is "replaced" within the buffer.

        StringBuilder result = new StringBuilder();
        if (tag == "del") return result; // if surroundng tag is del - returns empty result
        bool isTag = false; // indicates if we are reading the tag name
        bool inTag = false; // indicates if we are reading the text between pair of tags
        StringBuilder anyTag = new StringBuilder(); // holds the tag name of any found tag in the text
        StringBuilder openTag = new StringBuilder(); // holds the tag name of the relevant opening tag
        StringBuilder toEvaluate = new StringBuilder(); // holds the text between a pair of tags
        int nestedEqualTags = 0; // counts how many equal opening tags are found (the same number of closing tags we must have to make a pair)

        for (int i = 0; i < buffer.Length; i++)
        {
            char symbol = buffer[i];
            if (!isTag && symbol == '<') // tag start
            {
                isTag = true;
                continue;
            }

            if (isTag && symbol == '>') // tag end
            {
                isTag = false;
                if (openTag.Length == 0) // we don't have any opening tags up to the moment
                {
                    openTag.Append(anyTag);
                    inTag = true;
                    anyTag.Clear();
                }
                else
                {
                    if (openTag.Equals(anyTag)) nestedEqualTags++; // a new equal opening tag has been found - counts it
                    if (anyTag[0] == '/' && openTag.ToString() == anyTag.ToString(1, anyTag.Length - 1) && nestedEqualTags == 0)
                    // the closing tag that makes pair with the opening tag has been found
                    {
                        inTag = false;
                        // we already have a pair of tags inside the buffer - evaluates it
                        toEvaluate = Evaluate(toEvaluate, openTag.ToString());
                        // and then saves the result into buffer but after current position
                        if (i == buffer.Length - 1) // if end of buffer has been found
                        {
                            buffer.Append(toEvaluate); // appends it to the end of buffer
                        }
                        else
                        {
                            buffer.Insert(i+1, toEvaluate); // otherwise iserts it
                        }
                        anyTag.Clear();
                        openTag.Clear();
                        toEvaluate.Clear(); // clears all tag holders
                    }
                    else // we don't have a pair of tags or the pair is not the most outer one
                    {
                        // if we have more than one equal opening tags - counts the inner pair of them
                        if (anyTag[0] == '/' && openTag.ToString() == anyTag.ToString(1, anyTag.Length - 1)) nestedEqualTags--;
                        // since this is not the most outer tag puts it to the evaluation buffer
                        toEvaluate.Append("<" + anyTag + ">");
                        anyTag.Clear(); // clears the tag appended already
                    }
                }
                continue; // goes to the next buffer position
            }

            if (!isTag && !inTag) // standard output
            {
                switch (tag) // do the job of the corresponding tag
                {
                    case "upper":
                        result.Append(char.ToUpper(symbol));
                        break;
                    case "lower":
                        result.Append(char.ToLower(symbol));
                        break;
                    case "toggle":
                        if (Char.IsUpper(symbol)) result.Append(char.ToLower(symbol)); // toggles the case of the character
                        else result.Append(char.ToUpper(symbol));
                        break;
                    case "rev":
                        result.Insert(0, symbol); // text reversing is implemented through insert at the current buffer begining
                        break;
                    default:
                        result.Append(symbol); // normal text is just appended to the end of the current buffer
                        break;
                }
            }
            else if (isTag) //we are reading tag name
            {
                anyTag.Append(symbol);
            }
            else // we are in nested tag - just append to the evaluation buffer for further processing
            {
                toEvaluate.Append(symbol);
            }

//.........这里部分代码省略.........
开发者ID:psotirov,项目名称:TelerikAcademyProjects,代码行数:101,代码来源:Problem4.cs

示例5: Main

    public static int Main(string[] args)
    {
        string strManaged = "Managed";
        string strRet = "a";

        StringBuilder strBRet = new StringBuilder("a", 1);
        string strNative = " Native";
        StringBuilder strBNative = new StringBuilder(" Native", 7);

        Console.WriteLine("[Calling PInvokeDef.Marshal_InOut]");
        //since the out attributes doesnt work for string, so i dont check the out value.
        string strPara2 = new string(strManaged.ToCharArray());
        string strRet2 = PInvokeDef.Marshal_InOut(strPara2);
        if (!strRet2.Equals(strRet))
        {
            ReportFailure("Method PInvokeDef.Marshal_InOut[Managed Side],The Return string is wrong", strRet, strRet2);
        }

        //TestMethod3
        Console.WriteLine("[Calling PInvokeDef.Marshal_Out]");
        string strPara3 = strManaged;
        string strRet3 = PInvokeDef.Marshal_Out(strPara3);
        if (!strRet.Equals(strRet3))
        {
            ReportFailure("Method PInvokeDef.Marshal_Out[Managed Side],The Return string is wrong", strRet, strRet3);
        }
        if (!strManaged.Equals(strPara3))
        {
            ReportFailure("Method PInvokeDef.Marshal_Out[Managed Side],The Parameter string is Changed", strManaged, strPara3);
        }
        
        //TestMethod5
        Console.WriteLine("[Calling PInvokeDef.MarshalPointer_InOut]");
        string strPara5 = strManaged;
        string strRet5 = PInvokeDef.MarshalPointer_InOut(ref strPara5);
        if (!strRet5.Equals(strRet))
        {
            ReportFailure("Method PInvokeDef.MarshalPointer_InOut[Managed Side],The Return string is wrong", strRet, strRet5);
        }
        if (!strPara5.Equals(strNative))
        {
            ReportFailure("Method PInvokeDef.MarshalPointer_InOut[Managed Side],The Passed string is wrong", strNative, strPara5);
        }

        //TestMethod6
        Console.WriteLine("[Calling PInvokeDef.MarshalPointer_Out]");
        string strPara6;// = String.Copy(strManaged);
        string strRet6 = PInvokeDef.MarshalPointer_Out(out strPara6);
        if (!strRet6.Equals(strRet))
        {
            ReportFailure("Method PInvokeDef.MarshalPointer_Out[Managed Side],The Return string is wrong", strRet, strRet6);
        }
        if (!strPara6.Equals(strNative))
        {
            ReportFailure("Method PInvokeDef.MarshalPointer_Out[Managed Side],The Passed string is wrong", strNative, strPara6);
        }


        //TestMethod7
        Console.WriteLine("[Calling PInvokeDef.MarshalStrB_InOut]");
        StringBuilder strPara7 = new StringBuilder(strManaged);
        StringBuilder strRet7 = PInvokeDef.MarshalStrB_InOut(strPara7);

        if (!IsEqual(strRet7,strBRet))
        {
            ReportFailure("Method PInvokeDef.MarshalStrB_InOut[Managed Side],The Return string is wrong", strRet, strRet7.ToString());
        }
        if (!strPara7.Equals(new StringBuilder(strNative)))
        {
            ReportFailure("Method PInvokeDef.MarshalStrB_InOut[Managed Side],The Passed string is wrong", strNative, strPara7.ToString());
        }

        //TestMethod8
        Console.WriteLine("[Calling PInvokeDef.MarshalStrB_Out]");
        StringBuilder strPara8;// = new StringBuilder(strManaged);
        StringBuilder strRet8 = PInvokeDef.MarshalStrB_Out(out strPara8);
        if (!IsEqual(strRet8, strBRet))
        {
            ReportFailure("Method PInvokeDef.MarshalStrB_Out[Managed Side],The Return string is wrong", strRet, strRet8.ToString());
        }
        if (!IsEqual(strPara8,strBNative))
        {
            ReportFailure("Method PInvokeDef.MarshalStrB_Out[Managed Side],The Passed string is wrong", strNative, strPara8.ToString());
        }
        
        //TestMethod9
        Console.WriteLine("[Calling PInvokeDef.MarshalStrWB_InOut]");
        StringBuilder strPara9 = new StringBuilder(strManaged, strManaged.Length);
        StringBuilder strRet9 = PInvokeDef.MarshalStrWB_InOut(strPara9);
        
        if (!IsEqual(strRet9, strBRet))
        {
            ReportFailure("Method PInvokeDef.MarshalStrWB_InOut[Managed Side],The Return string is wrong", strRet, strRet9.ToString());
        }
        if (!IsEqual(strPara9,strBNative))
        {
            ReportFailure("Method PInvokeDef.MarshalStrWB_InOut[Managed Side],The Passed string is wrong", strNative, strPara9.ToString());
        }

        #region DelegatePinvoke
//.........这里部分代码省略.........
开发者ID:CheneyWu,项目名称:coreclr,代码行数:101,代码来源:LPTSTRTest.cs

示例6: TestEquals

 public static void TestEquals(StringBuilder sb1, StringBuilder sb2, bool expected)
 {
     Assert.Equal(expected, sb1.Equals(sb2));
 }
开发者ID:benpye,项目名称:corefx,代码行数:4,代码来源:StringBuilder.cs


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