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


C# StringBuilder.CopyTo方法代码示例

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


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

示例1: GeneratePassword

        internal string GeneratePassword(string userName)
        {
            // Create array of 10 letters based on last name, first name
            var builder = new StringBuilder();
            builder.Append(userName);
            if (builder.Length < 10)
            {
                builder.Append("qwertyuiopas");
            }
            var chars = new char[10];
            builder.CopyTo(0, chars, 0, 10);

            builder.Length = 0;

            // Create 6 digit random number to pick letters
            var seed = Utility.GetRandom(999999);
            // Pick letter for each digit
            for (int i = 0; i < 6; i++)
            {
                int digit;
                seed = Math.DivRem(seed, 10, out digit);
                builder.Append(chars[digit]);
            }
            // Append another 5 digit random number
            builder.Append(Utility.GetRandom(99999));
            return builder.ToString();
        }
开发者ID:BogamSushil,项目名称:OnlineGrocery,代码行数:27,代码来源:AuthenticationService.cs

示例2: Substring

        public static SqlString Substring(this ISqlString source, int offset, int count)
        {
            if (source == null || source.IsNull)
                return SqlString.Null;

            var en = source.GetEnumerator();
            var sb = new StringBuilder(count);

            int index = -1;
            while (en.MoveNext()) {
                if (++index < offset)
                    continue;

                sb.Append(en.Current);

                if (index == count - 1)
                    break;
            }

            #if PCL
            var s = sb.ToString();
            return new SqlString(s);
            #else
            var chars = new char[count];
            sb.CopyTo(0, chars, 0, count);
            return new SqlString(chars);
            #endif
        }
开发者ID:prepare,项目名称:deveeldb,代码行数:28,代码来源:SqlStringExtensions.cs

示例3: Encode

        public static string Encode(byte[] plaintext)
        {
            ContractsCommon.NotNull(plaintext, "plaintext");
            ContractsCommon.ResultIsNonNull<string>();

            var plaintextArr = new byte[plaintext.Length + 1];
            Array.Copy(plaintext, 0, plaintextArr, 1, plaintext.Length);
            Array.Reverse(plaintextArr);
            var workingValue = new BigInteger(plaintextArr);
            StringBuilder sb = new StringBuilder(plaintext.Length * 138 / 100 + 1);
            while (workingValue.CompareTo(BigInteger.Zero) > 0)
            {
                BigInteger remainder;
                workingValue = BigInteger.DivRem(workingValue, Base, out remainder);
                sb.Append(Alphabet[(int)remainder]);
            }
            Contract.Assert(workingValue.Sign >= 0);
            //sb.Insert(0, Alphabet[(int)workingValue]);

            for (int i = 0; i < plaintext.Length && plaintext[i] == 0; ++i)
            {
                sb.Append(Alphabet[0]);
            }

            var retVal = new char[sb.Length];
            sb.CopyTo(0, retVal, 0, sb.Length);
            Array.Reverse(retVal);
            return new string(retVal);
        }
开发者ID:neoeinstein,项目名称:xpdm.Bitcoin,代码行数:29,代码来源:Base58Convert.cs

示例4: PrecedesVowel

        internal bool PrecedesVowel(StringBuilder sb)
        {
            if (sb.Length == 0) return false;
            char c;
            int start = -1;
            int end = 0;
            for (int i = 0; i < sb.Length; i++)
            {
                c = sb[i];
                if (start == -1)
                {
                    if (Char.IsWhiteSpace(c) || Char.IsSeparator(c)) continue; // Must be padding, skip it
                    if (!Char.IsLetterOrDigit(c)) continue;
                    start = i;
                    if (i == sb.Length - 1) end = start + 1; // Word is one character long
                }
                else
                {
                    end = i;
                    if (!Char.IsLetterOrDigit(c)) break;
                    if (i == sb.Length - 1) end++; // Consume character if it's the last one in the buffer
                }
            }

            if (start == -1) return false;

            var buffer = new char[end - start];
            sb.CopyTo(start, buffer, 0, end - start);
            return _rules.Check(new string(buffer));
        }
开发者ID:katnapper323,项目名称:Rant,代码行数:30,代码来源:IndefiniteArticles.cs

示例5: AppendBuilder

 public static StringBuilder AppendBuilder(this StringBuilder sb, StringBuilder append)
 {
     var size = append.Length;
     int pos = 0;
     var buf = new char[4096];
     while (size > 0)
     {
         int len = size > 4096 ? 4096 : size;
         append.CopyTo(pos, buf, 0, len);
         sb.Append(buf, 0, len);
         pos += 4096;
         size -= 4096;
     }
     return sb;
 }
开发者ID:nutrija,项目名称:revenj,代码行数:15,代码来源:StreamOperations.cs

示例6: LexicalAnalizer

        public LexicalAnalizer(string solutionFile)
        {
            StringBuilder data = new StringBuilder();
            using (StreamReader reader = new StreamReader(solutionFile))
            {
                data.Append(reader.ReadToEnd());
            }

            if (data.Length > 0)
            {
                data.Append("\n");
                data = data.Replace("\r", ""); // remove the /r, for easy parsing
                char[] arr = new char[data.Length];
                data.CopyTo(0, arr, 0, data.Length);
                tokenData = Tokenize(arr);
            }
        }
开发者ID:tocsleung,项目名称:npanday,代码行数:17,代码来源:LexicalAnalizer.cs

示例7: ReplaceEntity

 static int ReplaceEntity(StringBuilder sb, int i)
 {
     int start = i;
     while (++i < sb.Length && sb[i] != ';') ;
     if (i == sb.Length) throw new ArgumentException("Could not find closing ';' for '&' at position " + start + ".");
     int length = i - start + 1;
     char[] chars = new char[length];
     sb.CopyTo(start, chars, 0, length);
     if (chars[1] != '#') // ignore numeric entities
     {
         var entity = new string(chars);
         string numericCode;
         if (entityMap.TryGetValue(entity, out numericCode))
         {
             sb.Remove(start, length);
             sb.Insert(start, numericCode);
         }
     }
     return i;
 }
开发者ID:modulexcite,项目名称:hotmod,代码行数:20,代码来源:HtmlEntityHelper.cs

示例8: button2_Click

        private void button2_Click(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder(richTextBox1.TextLength);
            sb.Append(richTextBox1.Text);
            richTextBox1.Text = "";
            int idx = 0;
            int amount = Math.Min((int)numericUpDown1.Value, sb.Length);
            char[] ar = new char[(int)numericUpDown1.Value];

            while (sb.Length >= (idx + amount))
            {
                sb.CopyTo(idx, ar, 0, amount);
                richTextBox1.AppendText(new string(ar) + "\n");
                Array.Clear(ar, 0, ar.Length);
                idx = idx + amount;
                if (sb.Length > idx)
                {
                    amount = Math.Min((int)numericUpDown1.Value, sb.Length - idx);
                }
            }
        }
开发者ID:aik-jahoda,项目名称:OndrasLearningSolutions,代码行数:21,代码来源:Form1.cs

示例9: save_text

        /*
        ** Name: save_text
        **
        ** Description:
        **	Copies text from a string buffer into the SQL text character array.
        **	Array is expanded if necessary.  String buffer is emptied.
        **
        ** Input:
        **	buff	String buffer.
        **
        ** Output:
        **	None.
        **
        ** Returns:
        **	void
        **
        ** History:
        **	20-Aug-01 (gordy)
        **	    Created.
        */
        private void save_text( StringBuilder buff )
        {
            /*
            ** Expand text array if needed.
            */
            if ( buff.Length > text.Length )
                text = new char[ buff.Length ];
            txt_len = buff.Length;

            //			buff.getChars( 0, txt_len, text, 0 );
            buff.CopyTo(0, text, 0, txt_len);

            buff.Length = 0;
            return;
        }
开发者ID:JordanChin,项目名称:Ingres,代码行数:35,代码来源:sqlparse.cs

示例10: CopyFromStringBuiler

 protected static char[] CopyFromStringBuiler(StringBuilder stBuilder, int start, int len)
 {
     char[] copyBuff = new char[len];
     stBuilder.CopyTo(start, copyBuff, 0, len);
     return copyBuff;
 }
开发者ID:prepare,项目名称:WebParser,代码行数:6,代码来源:SubLexer.cs

示例11: CreateIndexAsync


//.........这里部分代码省略.........
                    int charsUsed = 0;
                    bool completed = false;

                    // Convert the text to UTF8

                    utf8.Convert(blockBuf, 0, (int)loadedLength, charBuf, 0, charBuf.Length, i == totalBlocks - 1, out bytesUsed, out charsUsed, out completed);

                    if (!completed)
                    {
                        throw new Exception("UTF8 decoder could not complete the conversion");
                    }

                    // Construct a current string

                    sb.Length = 0;

                    if (charCarryOver.Length > 0)
                    {
                        sb.Append(charCarryOver);
                    }

                    sb.Append(charBuf, 0, charsUsed);

                    int carryOverLength = charCarryOver.Length;

                    int charsMatched = IndexString(sb.ToString(), beginnings[i], ends[i], carryOverLength, i == totalBlocks - 1);

                    // There's a Wiki topic carryover, let's store the characters which need to be carried over

                    if (charsMatched > 0)
                    {
                        charCarryOver = new char[charsMatched];

                        sb.CopyTo(charsUsed + carryOverLength - charsMatched, charCarryOver, 0, charsMatched);
                    }
                    else
                    {
                        charCarryOver = new char[0];
                    }

                    #endregion
                }

                // Wait till all the threads finish

                while (activeThreads != 0)
                {
                    ReportProgress(0, IndexingProgress.State.Running, "Waiting for tokenizer threads to finish");

                    Thread.Sleep(TimeSpan.FromSeconds(5));
                }

                ReportProgress(0, IndexingProgress.State.Running, "Flushing documents to disk");

                Lucene.Net.Store.Directory dir = memoryIndexer.GetDirectory();

                memoryIndexer.Close();

                indexer.AddIndexes(new Lucene.Net.Store.Directory[] { dir });

                memoryIndexer = null;

                ReportProgress(0, IndexingProgress.State.Running, "Optimizing index");

                indexer.Optimize();
开发者ID:kipropesque,项目名称:RuralCafe,代码行数:66,代码来源:Indexer.cs

示例12: GetSingleContent

        public string GetSingleContent(string data, string template)
        {
            var templateParts = template.ToLower().Split('*');
            if (templateParts != null && templateParts.Length == 2)
            {
                templateParts[0] = ClearContent(templateParts[0]);
                templateParts[1] = ClearContent(templateParts[1]);
            }
            var content = new StringBuilder(data.ToLower());
            ClearContent(content);
            int startPos = content.Contains(templateParts[0]);
            if (startPos == -1) return string.Empty;
            int endPos = content.Contains(templateParts[1], startPos + templateParts[0].Length );
            if (startPos != -1 && endPos != -1)
            {
                char[] destination = new char[endPos - startPos + templateParts[0].Length];
                content.CopyTo(startPos + templateParts[0].Length, destination, 0, endPos - (startPos + templateParts[0].Length));
                string result = new string(destination);

                content = null;

                return result;//RemoveTags(result).Trim();
            }
            content = null;
            return string.Empty;//return result;
        }
开发者ID:MaxIakovliev,项目名称:asp.net-mvc-real-estate,代码行数:26,代码来源:HtmlParser.cs

示例13: GetInputBuffer

        private int GetInputBuffer(StringBuilder content, bool isUnc, out char[] buffer)
        {
            int length = content.Length;
            length += isUnc ? PathInternal.UncExtendedPrefixToInsert.Length : PathInternal.ExtendedPathPrefix.Length;
            buffer = new char[length];

            if (isUnc)
            {
                PathInternal.UncExtendedPathPrefix.CopyTo(0, buffer, 0, PathInternal.UncExtendedPathPrefix.Length);
                int prefixDifference = PathInternal.UncExtendedPathPrefix.Length - PathInternal.UncPathPrefix.Length;
                content.CopyTo(prefixDifference, buffer, PathInternal.ExtendedPathPrefix.Length, content.Length - prefixDifference);
                return prefixDifference;
            }
            else
            {
                int prefixSize = PathInternal.ExtendedPathPrefix.Length;
                PathInternal.ExtendedPathPrefix.CopyTo(0, buffer, 0, prefixSize);
                content.CopyTo(0, buffer, prefixSize, content.Length);
                return prefixSize;
            }
        }
开发者ID:JonHanna,项目名称:corefx,代码行数:21,代码来源:PathHelper.Windows.cs

示例14: DeserializeDate

		private static DateTime DeserializeDate (ref StringBuilder input)
		{
			var inChars = new char[11];
			input.CopyTo (0, inChars, 0, inChars.Length);
			DateTime result;
			if (!DateTime.TryParseExact (new string (inChars), "MM:dd:yyyy;", CultureInfo.InvariantCulture, DateTimeStyles.None, out result))
				throw new SerializationException ();
			input.Remove (0, inChars.Length);
			return result;
		}
开发者ID:nlhepler,项目名称:mono,代码行数:10,代码来源:TimeZoneInfo.Serialization.cs

示例15: CopyTo_Invalid

        public static void CopyTo_Invalid()
        {
            var builder = new StringBuilder("Hello");
            Assert.Throws<ArgumentNullException>("destination", () => builder.CopyTo(0, null, 0, 0)); // Destination is null

            Assert.Throws<ArgumentOutOfRangeException>("sourceIndex", () => builder.CopyTo(-1, new char[10], 0, 0)); // Source index < 0
            Assert.Throws<ArgumentOutOfRangeException>("sourceIndex", () => builder.CopyTo(6, new char[10], 0, 0)); // Source index > builder.Length

            Assert.Throws<ArgumentOutOfRangeException>("destinationIndex", () => builder.CopyTo(0, new char[10], -1, 0)); // Destination index < 0
            Assert.Throws<ArgumentOutOfRangeException>("count", () => builder.CopyTo(0, new char[10], 0, -1)); // Count < 0

            Assert.Throws<ArgumentException>(null, () => builder.CopyTo(5, new char[10], 0, 1)); // Source index + count > builder.Length
            Assert.Throws<ArgumentException>(null, () => builder.CopyTo(4, new char[10], 0, 2)); // Source index + count > builder.Length

            Assert.Throws<ArgumentException>(null, () => builder.CopyTo(0, new char[10], 10, 1)); // Destination index + count > destinationArray.Length
            Assert.Throws<ArgumentException>(null, () => builder.CopyTo(0, new char[10], 9, 2)); // Destination index + count > destinationArray.Length
        }
开发者ID:dotnet,项目名称:corefx,代码行数:17,代码来源:StringBuilderTests.cs


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