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


C# String.CopyTo方法代码示例

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


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

示例1: TypeLexer

 public TypeLexer(String s)
 {
     // Turn the string into a char array with a NUL terminator.
     char[] chars = new char[s.Length + 1];
     s.CopyTo(0, chars, 0, s.Length);
     _chars = chars;
     _index = 0;
 }
开发者ID:tijoytom,项目名称:corert,代码行数:8,代码来源:TypeLexer.cs

示例2: AssemblyNameLexer

 internal AssemblyNameLexer(String s)
 {
     // Convert string to char[] with NUL terminator. (An actual NUL terminator in the input string will be treated
     // as an actual end of string: this is compatible with desktop behavior.)
     char[] chars = new char[s.Length + 1];
     s.CopyTo(0, chars, 0, s.Length);
     _chars = chars;
     _index = 0;
 }
开发者ID:tijoytom,项目名称:corert,代码行数:9,代码来源:AssemblyNameLexer.cs

示例3: parseConsoleCommand

        /// <summary>
        /// Parses new console command
        /// </summary>
        /// <param name="Line">Command to parse</param>
        /// <param name="server">Current Server instance</param>
        public void parseConsoleCommand(String Line, Server server)
        {
            ConsoleSender cSender = new ConsoleSender(server);
            cSender.ConsoleCommand.Message = Line;
            Sender sender = new Sender();
            sender.Op = true;
            cSender.ConsoleCommand.Sender = sender;
            server.PluginManager.processHook(Hooks.CONSOLE_COMMAND, cSender.ConsoleCommand);
            if (cSender.ConsoleCommand.Cancelled)
            {
                return;
            }

            if (Line.Contains("\""))
            {
                String[] commands = new String[Line.Substring(0, Line.IndexOf("\"")).Split(' ').Length + Line.Substring(Line.LastIndexOf("\"")).Split(' ').Length - 1];
                String[] temp = Line.Substring(0, Line.IndexOf("\"")).Trim().Split(' ');
                String[] temp2 = Line.Substring(Line.LastIndexOf("\"") + 1).Trim().Split(' ');
                String[] temp3 = new String[temp.Length + 1];
                temp.CopyTo(temp3, 0);

                temp3[temp3.Length - 1] = Line.Substring(Line.IndexOf("\""), Line.LastIndexOf("\"") - Line.IndexOf("\"")).Remove(0,1);

                temp3.CopyTo(commands, 0);
                temp2.CopyTo(commands, temp3.Length);

                if (commands == null || commands.Length <= 0)
                {
                    Program.tConsole.WriteLine("Issue parsing Console Command for " + Hooks.CONSOLE_COMMAND.ToString());
                    return;
                }
                switchCommands(commands, cSender.ConsoleCommand.Sender);

            }
            else
            {
                String[] commands = Line.Trim().ToLower().Split(' ');

                if (commands == null || commands.Length <= 0)
                {
                    Program.tConsole.WriteLine("Issue parsing Console Command for " + Hooks.CONSOLE_COMMAND.ToString());
                    return;
                }
                switchCommands(commands, cSender.ConsoleCommand.Sender);
            }
        }
开发者ID:alexcassol,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:51,代码来源:CommandParser.cs

示例4: BuildFinalArray

 private string[] BuildFinalArray(String[] arr1, int count)
 {
     arr1.CopyTo(FinaleArray, count);
     return FinaleArray;
 }
开发者ID:BACKUPLIB,项目名称:Darkportalwow,代码行数:5,代码来源:GossipStruct.cs

示例5: StrArray

 //join 2 String arrays
 internal static String[] StrArray(String[] sa1, String[] sa2)
 {
     String[] ss = new String[sa1.Length + sa2.Length];
     sa1.CopyTo(ss, 0);
     sa2.CopyTo(ss, sa1.Length);
     return ss;
 }
开发者ID:bencz,项目名称:OrangeC,代码行数:8,代码来源:Strg.cs

示例6: regionMatches

 public static bool regionMatches(String orig, bool ignoreCase, int toffset,
     String other, int ooffset, int len)
 {
     char[] ta = new char[orig.Length];
     char[] pa = new char[other.Length];
     orig.CopyTo(0, ta, 0, orig.Length);
     int to = toffset;
     other.CopyTo(0, pa, 0, other.Length);
     int po = ooffset;
     // Note: toffset, ooffset, or len might be near -1>>>1.
     if ((ooffset < 0) || (toffset < 0) || (toffset > (long)orig.Length - len) ||
         (ooffset > (long)other.Length - len))
     {
         return false;
     }
     while (len-- > 0)
     {
         char c1 = ta[to++];
         char c2 = pa[po++];
         if (c1 == c2)
         {
             continue;
         }
         if (ignoreCase)
         {
             // If characters don't match but case may be ignored,
             // try converting both characters to uppercase.
             // If the results match, then the comparison scan should
             // continue.
             char u1 = char.ToUpper(c1);
             char u2 = char.ToUpper(c2);
             if (u1 == u2)
             {
                 continue;
             }
             // Unfortunately, conversion to uppercase does not work properly
             // for the Georgian alphabet, which has strange rules about case
             // conversion.  So we need to make one last check before
             // exiting.
             if (char.ToLower(u1) == char.ToLower(u2))
             {
                 continue;
             }
         }
         return false;
     }
     return true;
 }
开发者ID:akrisiun,项目名称:SharpSSH,代码行数:48,代码来源:Util.cs

示例7: WriteAsyncInternal

        // We pass in private instance fields of this MarshalByRefObject-derived type as local params
        // to ensure performant access inside the state machine that corresponds this async method.
        // Fields that are written to must be assigned at the end of the method *and* before instance invocations.
        private static async Task WriteAsyncInternal(StreamWriter _this, String value,
                                                     Char[] charBuffer, Int32 charPos, Int32 charLen, Char[] coreNewLine,
                                                     bool autoFlush, bool appendNewLine)
        {
            Contract.Requires(value != null);

            int count = value.Length;
            int index = 0;

            while (count > 0)
            {
                if (charPos == charLen) {
                    await _this.FlushAsyncInternal(false, false, charBuffer, charPos).ConfigureAwait(false);
                    Contract.Assert(_this.charPos == 0);
                    charPos = 0;
                }

                int n = charLen - charPos;
                if (n > count)
                    n = count;

                Contract.Assert(n > 0, "StreamWriter::Write(String) isn't making progress!  This is most likely a race condition in user code.");

                value.CopyTo(index, charBuffer, charPos, n);

                charPos += n;
                index += n;
                count -= n;
            }

            if (appendNewLine)
            {
                for (Int32 i = 0; i < coreNewLine.Length; i++)   // Expect 2 iterations, no point calling BlockCopy
                {
                    if (charPos == charLen) {
                        await _this.FlushAsyncInternal(false, false, charBuffer, charPos).ConfigureAwait(false);
                        Contract.Assert(_this.charPos == 0);
                        charPos = 0;
                    }

                    charBuffer[charPos] = coreNewLine[i];
                    charPos++;
                }
            }

            if (autoFlush) {
                await _this.FlushAsyncInternal(true, false, charBuffer, charPos).ConfigureAwait(false);
                Contract.Assert(_this.charPos == 0);
                charPos = 0;
            }

            _this.CharPos_Prop = charPos;
        }
开发者ID:Rayislandstyle,项目名称:dotnet-coreclr,代码行数:56,代码来源:StreamWriter.cs

示例8: AppendString

        private void AppendString(String value)
        {
            int valueLength;
            int lengthEncodingSize;
            int nextTop;


            valueLength = value.Length;

            lengthEncodingSize = valueLength >= 0x8000 ? 2 : 1;
            
            nextTop = this._sourceTop + lengthEncodingSize + valueLength;
            
            if (nextTop > this._sourceBuffer.Length)
            {
                this.IncreaseSourceCapacity(nextTop);
            }

            if (valueLength >= 0x8000)
            {
                // Use 2 chars to encode strings exceeding 32K, were the highest
                // bit in the first char indicates presence of the next byte
                // NOTE: There is no '>>>' in C#. Handle it via unsigned, shift, signed.
                //       Info found here: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1690218&SiteID=1
                uint x = Convert.ToUInt32(valueLength);
                this._sourceBuffer[this._sourceTop] = Convert.ToChar(0x8000 | Convert.ToInt32(x >> 16));
                this._sourceTop++;
            }

            this._sourceBuffer[this._sourceTop] = Convert.ToChar(valueLength);
            this._sourceTop++;
            value.CopyTo(0,
                this._sourceBuffer,
                this._sourceTop,
                valueLength);
            this._sourceTop = nextTop;
        }
开发者ID:jzabroski,项目名称:YUICompressor.NET,代码行数:37,代码来源:Decompiler.cs

示例9: Union

 private String[] Union(String[] a1, String[] a2)
 {
     String[] tot = new String[a1.Length + a2.Length];
     a1.CopyTo(tot, 0);
     a2.CopyTo(tot, a1.Length);
     return tot;
 }
开发者ID:andva,项目名称:Eulerian-ShootEmUp,代码行数:7,代码来源:ConsoleScene.cs

示例10: WriteLine

        // Writes a string followed by a line terminator to the text stream.
        //
        public virtual void WriteLine(String value) {

            if (value==null) {
                WriteLine();
            }
            else {
                // We'd ideally like WriteLine to be atomic, in that one call
                // to WriteLine equals one call to the OS (ie, so writing to 
                // console while simultaneously calling printf will guarantee we
                // write out a string and new line chars, without any interference).
                // Additionally, we need to call ToCharArray on Strings anyways,
                // so allocating a char[] here isn't any worse than what we were
                // doing anyways.  We do reduce the number of calls to the 
                // backing store this way, potentially.
                int vLen = value.Length;
                int nlLen = CoreNewLine.Length;
                char[] chars = new char[vLen+nlLen];
                value.CopyTo(0, chars, 0, vLen);
                // CoreNewLine will almost always be 2 chars, and possibly 1.
                if (nlLen == 2) {
                    chars[vLen] = CoreNewLine[0];
                    chars[vLen+1] = CoreNewLine[1];
                }
                else if (nlLen == 1)
                    chars[vLen] = CoreNewLine[0];
                else
                    Buffer.InternalBlockCopy(CoreNewLine, 0, chars, vLen * 2, nlLen * 2);
                Write(chars, 0, vLen + nlLen);
            }
            /*
            Write(value);  // We could call Write(String) on StreamWriter...
            WriteLine();
            */
        }
开发者ID:uQr,项目名称:referencesource,代码行数:36,代码来源:textwriter.cs

示例11: minMax

        private float minMax(String[] board, List<int> freeSpace, String aiMark, float bestScore)
        {
            int rows = (int)(Math.Sqrt(board.Length));
            int cols = rows;

            float avgCount = 0;
            float avgProb = 0;
            String[] tempBoard = new String[rows * cols];
            String[] tempBoardP = new String[rows * cols];
            board.CopyTo(tempBoard, 0);

            int aiID = 0;
            int playerID = 0;
            if (aiMark == "X")
            {
                aiID = 1;
                playerID = 2;
            }
            else
            {
                aiID = 2;
                playerID = 1;
            }


            if (victoryCheck(board) == aiID || victoryCheck(board) == 4)
            {
                //this is a winning leaf
                return 1;
            }
            else if (victoryCheck(board) == playerID)
            {
                //this is a losing leaf
                return 0;
            }

            else
            {
                //if not a tie, win, or loss, then there are more moves to make.
                for (int x = 0; x < freeSpace.Count; x++)
                {
                    List<int> passIn = new List<int>(freeSpace);
                    passIn.RemoveAt(x);

                    board.CopyTo(tempBoard, 0);
                    tempBoard[freeSpace[x]] = aiMark;

                    //did we win?
                    if (victoryCheck(tempBoard) == aiID || victoryCheck(tempBoard) == 4)
                    {
                        //this is a winning leaf
                        return 1;
                    }

                    if (passIn.Count > 0)
                    {
                        //player's possible response if we didn't win
                        for (int y = 0; y < passIn.Count; y++)
                        {
                            tempBoard.CopyTo(tempBoardP, 0);
                            if (aiMark == "X")
                            {
                                tempBoardP[passIn[y]] = "O";
                            }
                            else
                            {
                                tempBoardP[passIn[y]] = "X";
                            }
                            //displayGameBoard(tempBoardP);


                            List<int> pResponse = new List<int>(passIn);
                            pResponse.RemoveAt(y);
                            avgProb += minMax(tempBoardP, pResponse, aiMark, bestScore);
                            avgCount++;

                            if (((avgProb - (((y + 1) + ((x + 1) * passIn.Count)))) + 1) / ((passIn.Count) * (freeSpace.Count)) < bestScore)
                            {
                                //give up bad branch
                                //prune
                                //return 0;
                            }
                        }
                    }
                    else
                    {
                        avgProb += minMax(tempBoard, passIn, aiMark, bestScore);
                        avgCount++;
                    }
                }
                return (avgProb / avgCount);
            }
        }
开发者ID:nikyusof,项目名称:tictactoe,代码行数:93,代码来源:TicTacToe.cs

示例12: DecideWithAttractiveness

        private int DecideWithAttractiveness()
        {
            int len = _unusedSlots.Count;

            String[] board = new String[_tiles.Count];
            for (int i = 0; i < len; ++i)
            {
                board[i] = GetVisualMark(_tiles[i].mark);
            }

            String aiMark = _playerStartedFirst ? "O" : "X";

            int aiID = 0;
            int playerID = 0;

            if (aiMark == "X")
            { // AI started first
                aiID = 1;
                playerID = 2;
            }
            else
            { // player started first
                aiID = 2;
                playerID = 1;
            }

            String[] tempBoard = new String[_tiles.Count];
            String[] tempBoardP = new String[_tiles.Count];

            board.CopyTo(tempBoard, 0);
            float prob = 0;
            float probCount = 0;
            float maxProb = 0;
            int maxIndex = 0;

            for (int x = 0; x < _unusedSlots.Count; x++)
            {
                List<int> passIn = new List<int>(_unusedSlots);
                passIn.RemoveAt(x);

                board.CopyTo(tempBoard, 0);
                tempBoard[_unusedSlots[x]] = aiMark;

                // NOTE: This should have been resolved from the generic case. uncomment to make sure later
                //did we win?
                if (victoryCheck(tempBoard) == aiID)// || victoryCheck(tempBoard) == 4) // draw case should be handled by generic case
                {
                    //this is a winning leaf
                    maxIndex = x;
                    throw new Exception("Error: This should've been handled by the Generic Cases.");
                    //break;
                }

                if (passIn.Count > 0)
                {
                    //player's possible response if we didn't win
                    for (int y = 0; y < passIn.Count; y++)
                    {
                        tempBoard.CopyTo(tempBoardP, 0);
                        if (aiMark == "X")
                        {
                            tempBoardP[passIn[y]] = "O";
                        }
                        else
                        {
                            tempBoardP[passIn[y]] = "X";
                        }

                        List<int> pResponse = new List<int>(passIn);
                        pResponse.RemoveAt(y);
                        prob += minMax(tempBoardP, pResponse, aiMark, maxProb);
                        probCount++;
                    }
                }
                if ((prob / probCount) > maxProb)
                {
                    maxIndex = x;
                    maxProb = prob / probCount;
                }
                probCount = 0;
                prob = 0;
            }

            return _unusedSlots[maxIndex];
        }
开发者ID:nikyusof,项目名称:tictactoe,代码行数:85,代码来源:TicTacToe.cs

示例13: Write

        public override void Write(String value)
        {
            if (value != null)
            {

                int count = value.Length;
                int index = 0;
                while (count > 0)
                {
                    if (charPos == charLen) Flush(false, false);
                    int n = charLen - charPos;
                    if (n > count) n = count;
                    value.CopyTo(index, charBuffer, charPos, n);
                    charPos += n;
                    index += n;
                    count -= n;
                }
                if (autoFlush) Flush(true, false);
            }
        }
开发者ID:afrog33k,项目名称:csnative,代码行数:20,代码来源:StreamWriter.cs

示例14: Unpack

        /// <summary>
        /// "Распаковка" имени файла из префиксного формата в исходный
        /// </summary>
        /// <param name="filename">Имя файла для "распаковки"</param>
        /// <param name="volNum">Номер текущего тома</param>
        /// <param name="dataCount">Количество основных томов</param>
        /// <param name="eccCount">Количество томов для восстановления</param>
        /// <returns>Булевский флаг операции</returns>
        public bool Unpack(ref String filename, ref int volNum, ref int dataCount, ref int eccCount)
        {            
            // Если имя файла для распаковки содержит менее одного символа
            // за исключением префикса, или если упакованное имя файла не
            // содержит специфического символа в начале и точки в конце,
            // то отказываем в обработке
            if (
                    (filename.Length < 15)
                 ||
                    (filename[0] != '@')
                 ||
                    (filename[13] != '.')
                )
            {
                return false;
            }

            // Инициализируем массив для хранения набора символов "HEX-представления"
            Char[] prefixPartChr = new Char[12];

            // Копируем данные "HEX-представления" volNum, dataCount, eccCount в массив Char
            filename.CopyTo(1, prefixPartChr, 0, 12);

            // Извлекаем номер тома            
            if (!HEXToInt16(ref volNum, prefixPartChr, 0))
            {
                return false;
            }

            // Извлекаем количество основных томов            
            if (!HEXToInt16(ref dataCount, prefixPartChr, 4))
            {
                return false;
            }

            // Извлекаем количество томов для восстановления
            if (!HEXToInt16(ref eccCount, prefixPartChr, 8))
            {
                return false;
            }

            // Убираем префикс из имени файла
            filename = filename.Substring(14, (filename.Length - 14));

            return true;
        }
开发者ID:Alenochka17,项目名称:laba3,代码行数:54,代码来源:FileNamer.cs

示例15: Write

	// Write a string to the stream writer.
	public override void Write(String value)
			{
				if(value == null)
					return;
				int temp;
				int index = 0;
				int count = value.Length;
				if(stream == null)
				{
					throw new ObjectDisposedException(_("IO_StreamClosed"));
				}
				while(count > 0)
				{
					temp = bufferSize - inBufferLen;
					if(temp > count)
					{
						temp = count;
					}
					value.CopyTo(index, inBuffer, inBufferLen, temp);
					index += temp;
					count -= temp;
					inBufferLen += temp;
					if(inBufferLen >= bufferSize)
					{
						Convert(false);
					}
				}
				if(autoFlush)
				{
					Convert(false);
					stream.Flush();
				}
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:34,代码来源:StreamWriter.cs


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