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


C# StringBuffer.Append方法代码示例

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


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

示例1: CustomFormat

 static void CustomFormat(StringBuffer buffer, Blah blah, StringView format)
 {
     if (format == "yes")
         buffer.Append("World!");
     else
         buffer.Append("(Goodbye)");
 }
开发者ID:aka-STInG,项目名称:StringFormatter,代码行数:7,代码来源:Program.cs

示例2: ReduceLength

 public void ReduceLength()
 {
     using (var buffer = new StringBuffer())
     {
         buffer.Append("Food");
         Assert.Equal((uint)5, buffer.CharCapacity);
         buffer.Length = 3;
         Assert.Equal("Foo", buffer.ToString());
         // Shouldn't reduce capacity when dropping length
         Assert.Equal((uint)5, buffer.CharCapacity);
     }
 }
开发者ID:ESgarbi,项目名称:corefx,代码行数:12,代码来源:StringBufferTests.cs

示例3: CreateFromString

        public unsafe void CreateFromString()
        {
            string testString = "Test";
            using (var buffer = new StringBuffer())
            {
                buffer.Append(testString);
                Assert.Equal((uint)testString.Length, buffer.Length);
                Assert.Equal((uint)testString.Length + 1, buffer.CharCapacity);

                for (int i = 0; i < testString.Length; i++)
                {
                    Assert.Equal(testString[i], buffer[(uint)i]);
                }

                // Check the null termination
                Assert.Equal('\0', buffer.CharPointer[testString.Length]);

                Assert.Equal(testString, buffer.ToString());
            }
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:20,代码来源:StringBufferTests.cs

示例4: TryExpandShortFileName

        private unsafe static string TryExpandShortFileName(StringBuffer outputBuffer, string originalPath)
        {
            // We guarantee we'll expand short names for paths that only partially exist. As such, we need to find the part of the path that actually does exist. To
            // avoid allocating like crazy we'll create only one input array and modify the contents with embedded nulls.

            Contract.Assert(!PathInternal.IsPartiallyQualified(outputBuffer), "should have resolved by now");

            using (StringBuffer inputBuffer = new StringBuffer(outputBuffer))
            {
                bool success = false;
                uint lastIndex = outputBuffer.Length - 1;
                uint foundIndex = lastIndex;
                uint rootLength = PathInternal.GetRootLength(outputBuffer);

                while (!success)
                {
                    uint result = Win32Native.GetLongPathNameW(inputBuffer.GetHandle(), outputBuffer.GetHandle(), outputBuffer.CharCapacity);

                    // Replace any temporary null we added
                    if (inputBuffer[foundIndex] == '\0') inputBuffer[foundIndex] = '\\';

                    if (result == 0)
                    {
                        // Look to see if we couldn't find the file
                        int error = Marshal.GetLastWin32Error();
                        if (error != Win32Native.ERROR_FILE_NOT_FOUND && error != Win32Native.ERROR_PATH_NOT_FOUND)
                        {
                            // Some other failure, give up
                            break;
                        }

                        // We couldn't find the path at the given index, start looking further back in the string.
                        foundIndex--;

                        for (; foundIndex > rootLength && inputBuffer[foundIndex] != '\\'; foundIndex--) ;
                        if (foundIndex == rootLength)
                        {
                            // Can't trim the path back any further
                            break;
                        }
                        else
                        {
                            // Temporarily set a null in the string to get Windows to look further up the path
                            inputBuffer[foundIndex] = '\0';
                        }
                    }
                    else if (result > outputBuffer.CharCapacity)
                    {
                        // Not enough space. The result count for this API does not include the null terminator.
                        outputBuffer.EnsureCharCapacity(result);
                    }
                    else
                    {
                        // Found the path
                        success = true;
                        outputBuffer.Length = result;
                        if (foundIndex < lastIndex)
                        {
                            // It was a partial find, put the non-existant part of the path back
                            outputBuffer.Append(inputBuffer, foundIndex, inputBuffer.Length - foundIndex);
                        }
                    }
                }

                StringBuffer bufferToUse = success ? outputBuffer : inputBuffer;

                if (bufferToUse.SubstringEquals(originalPath))
                {
                    // Use the original path to avoid allocating
                    return originalPath;
                }

                return bufferToUse.ToString();
            }
        }
开发者ID:nietras,项目名称:coreclr,代码行数:75,代码来源:LongPathHelper.cs

示例5: AppendOverCountWithIndexThrows

 public void AppendOverCountWithIndexThrows()
 {
     using (var buffer = new StringBuffer())
     {
         Assert.Throws<ArgumentOutOfRangeException>(() => buffer.Append("A", startIndex: 1, count: 1));
     }
 }
开发者ID:rajeevkb,项目名称:corefx,代码行数:7,代码来源:StringBufferTests.cs

示例6: AppendNegativeIndexThrows

 public void AppendNegativeIndexThrows()
 {
     using (var buffer = new StringBuffer())
     {
         Assert.Throws<ArgumentOutOfRangeException>(() => buffer.Append("a", startIndex: -1));
     }
 }
开发者ID:rajeevkb,项目名称:corefx,代码行数:7,代码来源:StringBufferTests.cs

示例7: AppendNullStringBufferThrows

 public void AppendNullStringBufferThrows()
 {
     using (var buffer = new StringBuffer())
     {
         Assert.Throws<ArgumentNullException>(() => buffer.Append((StringBuffer)null));
     }
 }
开发者ID:rajeevkb,项目名称:corefx,代码行数:7,代码来源:StringBufferTests.cs

示例8: AppendTests

        public void AppendTests(string source, string value, int startIndex, int count, string expected)
        {
            // From string
            using (var buffer = new StringBuffer(source))
            {
                buffer.Append(value, startIndex, count);
                Assert.Equal(expected, buffer.ToString());
            }

            // From buffer
            using (var buffer = new StringBuffer(source))
            using (var valueBuffer = new StringBuffer(value))
            {
                if (count == -1)
                    buffer.Append(valueBuffer, (ulong)startIndex, valueBuffer.Length - (ulong)startIndex);
                else
                    buffer.Append(valueBuffer, (ulong)startIndex, (ulong)count);
                Assert.Equal(expected, buffer.ToString());
            }
        }
开发者ID:rajeevkb,项目名称:corefx,代码行数:20,代码来源:StringBufferTests.cs

示例9: StartsWith

 public void StartsWith(string source, string value, bool expected)
 {
     using (var buffer = new StringBuffer())
     {
         buffer.Append(source);
         Assert.Equal(expected, buffer.StartsWith(value));
     }
 }
开发者ID:ESgarbi,项目名称:corefx,代码行数:8,代码来源:StringBufferTests.cs

示例10: CopyToBufferString

        public void CopyToBufferString(string destination, string content, uint destinationIndex, uint bufferIndex, uint count, string expected)
        {
            using (var buffer = new StringBuffer())
            using (var destinationBuffer = new StringBuffer())
            {
                buffer.Append(content);
                destinationBuffer.Append(destination);

                buffer.CopyTo(bufferIndex, destinationBuffer, destinationIndex, count);
                Assert.Equal(expected, destinationBuffer.ToString());
            }
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:12,代码来源:StringBufferTests.cs

示例11: SubstringEqualsOverSizeCountWithIndexThrows

 public void SubstringEqualsOverSizeCountWithIndexThrows()
 {
     using (var buffer = new StringBuffer())
     {
         buffer.Append("A");
         Assert.Throws<ArgumentOutOfRangeException>(() => buffer.SubstringEquals("", startIndex: 1, count: 1));
     }
 }
开发者ID:ESgarbi,项目名称:corefx,代码行数:8,代码来源:StringBufferTests.cs

示例12: TrimEnd

        public void TrimEnd(string content, char[] trimChars, string expected)
        {
            // We want equivalence with built-in string behavior
            using (var buffer = new StringBuffer())
            {
                buffer.Append(content);

                buffer.TrimEnd(trimChars);
                Assert.Equal(expected, buffer.ToString());
            }
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:11,代码来源:StringBufferTests.cs

示例13: CopyFromString

        public void CopyFromString(string content, string source, uint bufferIndex, int sourceIndex, int count, string expected)
        {
            using (var buffer = new StringBuffer())
            {
                buffer.Append(content);

                buffer.CopyFrom(bufferIndex, source, sourceIndex, count);
                Assert.Equal(expected, buffer.ToString());
            }
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:10,代码来源:StringBufferTests.cs

示例14: SetLengthToFirstNullTests

        public unsafe void SetLengthToFirstNullTests(string content, ulong startLength, ulong endLength)
        {
            using (var buffer = new StringBuffer())
            {
                buffer.Append(content);

                // With existing content
                Assert.Equal(startLength, buffer.Length);
                buffer.SetLengthToFirstNull();
                Assert.Equal(endLength, buffer.Length);

                // Clear the buffer & manually copy in
                buffer.Length = 0;
                fixed (char* contentPointer = content)
                {
                    Buffer.MemoryCopy(contentPointer, buffer.CharPointer, (long)buffer.CharCapacity * 2, content.Length * sizeof(char));
                }

                Assert.Equal((uint)0, buffer.Length);
                buffer.SetLengthToFirstNull();
                Assert.Equal(endLength, buffer.Length);
            }
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:23,代码来源:StringBufferTests.cs

示例15: SetLengthToFirstNullNoNull

        public unsafe void SetLengthToFirstNullNoNull()
        {
            using (var buffer = new StringBuffer())
            {
                buffer.Append("A");

                // Wipe out the last null
                buffer.CharPointer[buffer.Length] = 'B';
                buffer.SetLengthToFirstNull();
                Assert.Equal((ulong)1, buffer.Length);
            }
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:12,代码来源:StringBufferTests.cs


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