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


C# String.Insert方法代码示例

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


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

示例1: cmd

        public String cmd(String cnd)
        {

            cnd = cnd.Trim();
            String output = " ";
            Console.WriteLine(cnd);

            if ((cnd.Substring(0, 3).ToLower() == "cd_") && (cnd.Length > 2))
            {

                if (System.IO.Directory.Exists(cnd.Substring(2).Trim()))
                    cpath = cnd.Substring(2).Trim();

            }
            else
            {
                cnd = cnd.Insert(0, "/B /c ");
                Process p = new Process();
                p.StartInfo.WorkingDirectory = cpath;
                p.StartInfo.CreateNoWindow = true;
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.Arguments = cnd;
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardOutput = true;
                p.Start();
                output = p.StandardOutput.ReadToEnd();  // output of cmd
                output = (output.Length == 0) ? " " : output;
                p.WaitForExit();

            }
            return output;
        } // end cmd 
开发者ID:TheBugMaker,项目名称:Payload-Client,代码行数:32,代码来源:Tools.cs

示例2: getDateTime

 /// <summary>
 /// Get DateTime from string
 /// </summary>
 /// <param name="dateTimeString">String containing DateTime</param>
 /// <returns>Object of DateTime</returns>
 internal static DateTime getDateTime(String dateTimeString)
 {
     DateTime dateTime;
     dateTimeString = dateTimeString.Insert(10, " ");
     dateTime = Convert.ToDateTime(dateTimeString);
     return dateTime;
 }
开发者ID:projectpvg1,项目名称:BE-Project,代码行数:12,代码来源:JSONParser.cs

示例3: capitalize

 private String capitalize(String text)
 {
     String first = text[0].ToString();
     text = text.Remove(0, 1);
     first = first.ToUpper();
     text = text.Insert(0, first);
     return text;
 }
开发者ID:RichardRanft,项目名称:RPGLifePath,代码行数:8,代码来源:CNameGenerator.cs

示例4: swapSecondAndThirdDigits

        private static String swapSecondAndThirdDigits(String str)
        {
            String tmp = str[1].ToString();
            str = str.Remove(1, 1);
            str = str.Insert(2, tmp);

            return str;
        }
开发者ID:mgulubov,项目名称:SoftUniCourse-ProgrammingBasics,代码行数:8,代码来源:FourDigitNumber.cs

示例5: CheckForImplicitMultiplication

 private static string CheckForImplicitMultiplication(String expression)
 {
     for (var i = 1; i < expression.Count() - 1; i++)
         if ((expression[i] == ')' && Char.IsNumber(expression[i + 1])) ||
            (expression[i] == '(' && Char.IsNumber(expression[i - 1])))
             expression = expression.Insert(i + 1, "*");
     return expression;
 }
开发者ID:neoprincie,项目名称:TheNewStringCalculator,代码行数:8,代码来源:Calculator.cs

示例6: ReplaceDocumentIDInMetadata

 /// <summary>
 /// Replace the document id in the given metadata
 /// </summary>
 /// <param name="metadata">A metadata string</param>
 /// <param name="documentid">The document id which should be inserted</param>
 /// <returns>Returns a metadata string with the new document id</returns>
 public static String ReplaceDocumentIDInMetadata(String metadata, int documentid)
 {
     int startIndex = metadata.IndexOf("docid") + 5;
     int endIndex = metadata.IndexOf("|");
     metadata = metadata.Remove(startIndex, endIndex - startIndex);
     metadata = metadata.Insert(startIndex, " " + documentid.ToString());
     return metadata;
 }
开发者ID:MikkelFunch,项目名称:sliceofpie,代码行数:14,代码来源:Metadata.cs

示例7: Read

        /// <summary>
        /// Reads matrix and branches (if exists) from specified file.
        /// </summary>
        /// <param name="filePath">File path.</param>
        /// <param name="networkSize">The size of the network (matrix, which represents the network).</param>
        /// <param name="matrixType">The type of given matrix (content of the specified file)</param>
        /// <returns>Matrix and branches (if exists).</returns>
        /// <throws>CoreException, MatrixFormatException.</throws>
        public static MatrixInfoToRead Read(String filePath, int networkSize, AdjacencyMatrixType matrixType)
        {
            MatrixInfoToRead result = new MatrixInfoToRead();

            result.Matrix = MatrixReader(filePath, networkSize, matrixType);
            result.Branches = BranchesReader(filePath.Insert(filePath.Length - 4, "_branches"));

            return result;
        }
开发者ID:aramazhari,项目名称:complexnetwork,代码行数:17,代码来源:FileManager.cs

示例8: CleanString

 public void CleanString(String s)
 {
     if (s.Length != 0) {
         s.Replace(" ", "");
         while (s.Length < 8) {
             s.Insert(0, "0");
         }
     }
 }
开发者ID:hoangqviet,项目名称:BaseConverter,代码行数:9,代码来源:MainWindow.xaml.cs

示例9: Tag

        public static string Tag(String rootRelativePath)
        {
            if (HttpRuntime.Cache[rootRelativePath] == null)
            {
                string absolute = HostingEnvironment.MapPath("~" + rootRelativePath);

                DateTime date = File.GetLastWriteTime(absolute);
                int index = rootRelativePath.LastIndexOf('/');

                string result = rootRelativePath.Insert(index, "/v-" + date.Ticks);
                HttpRuntime.Cache.Insert(rootRelativePath, result, new CacheDependency(absolute));
            }

            return HttpRuntime.Cache[rootRelativePath] as string;
        }
开发者ID:googaplexed,项目名称:JAPSite,代码行数:15,代码来源:Fingerprint.cs

示例10: _ConvertToStringFilePath

        public static String _ConvertToStringFilePath(String _filePath)
        {
            char searchChar = '\\';
            Int32 index = new Int32();

            while((index = _filePath.IndexOf(searchChar, index)) != -1)
            {
                if ((index + 1) < _filePath.Length && _filePath[index + 1] != searchChar)
                {
                    _filePath.Insert(index, searchChar.ToString());
                    index++;
                }

                index++;
            }

            return _filePath;
        }
开发者ID:pkim,项目名称:Hlib,代码行数:18,代码来源:TextFileManager.cs

示例11: ParseANSI

        private string ParseANSI(String s)
        {
            //統一用\n換行
            s = s.Replace( "\r\n", "\n" ).Replace( "\r", "\n" );

            //htmlspecialchars()
            s = s.Replace( "&", "&amp;" ).Replace( "<", "&lt;" ).Replace( ">", "&gt;" );

            /* TODO: 目前取時間有誤 */
            //解析作者、看板、標題、時間等資訊
            //s = Regex.Replace( s, "^(?:作者|發信人):\\s([^\\s]*)\\s\\(([^\\)]*)\\)\\s(站內|看板):\\s([^(\\r|\\n)]*)(?:\\r\\n|\\r|\\n)(?:標題|標  題):\\s([^(\\r|\\n)]*)(?:\\r\\n|\\r|\\n)(?:時間|發信站):\\s([^(\\r|\\n)]*)?\\s?\\(?(d{4}\\/\\d{2}\\/\\d{2}\\s(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)\\s\\d{2}:\\d{2}:\\d{2})\\)?"
            s = Regex.Replace( s, "^(?:作者|發信人):\\s([^\\s]*)\\s\\(([^\\)]*)\\)\\s(站內|看板):\\s([^\\n]*)\\n(?:標題|標  題):\\s([^\\n]*)\\n(?:時間|發信站):\\s([^\\n]*)"
                , "<div class=\"entry-meta\"><div class=\"author vcard\"><span class=\"label\">作者</span> <span class=\"nickname\">$1</span> (<span class=\"fn n\">$2</span>)</div><div class=\"board\"><span class=\"label\">$3</span> <span class=\"board-title\">$4</span></div><div class=\"entry-title\"><span class=\"label\">標題</span> <h1>$5</h1></div><div class=\"entry-date\"><span class=\"label\">時間</span> <span class=\"published\">$6</span></div></div>"
                , RegexOptions.Compiled );

            //找地方插入 <pre class="entry-content">
            int content_pos = s.Contains( "</div>\n" ) ? s.LastIndexOf( "</div>\n" ) + 7 : 0;
            s = s.Insert( content_pos, "<pre class=\"entry-content\">" );

            //解析「※」開頭文字
            s = Regex.Replace( s, "^※.*$", "<span class=\"quote\">$&</span>", RegexOptions.Multiline );

            /* TODO: 要作巢狀引文嗎? */
            //解析引文
            s = Regex.Replace( s, "^(?:&gt;|:)\\s.*$", "<blockquote>$&</blockquote>", RegexOptions.Multiline )
                .Replace( "</blockquote>\n<blockquote>", "\n" ); //移除多餘標注

            //取出控制碼,執行ANSI轉HTML
            s = Regex.Replace( s, "\u001B\\[([0-7;]*)m", new MatchEvaluator( this._ParseANSI ), RegexOptions.Compiled );

            //如果前面有未關閉的標籤,先關閉之
            s += opened == true ? "</span>" : "";

            //處理超連結
            s = Regex.Replace( s, "(https?|ftps?|telnet|mms|rtsp|ircs?|ed2k|ssh|svn|svn+ssh)://[0-9a-zA-Z/?|@:%&#~=$-_.+!*'()\\,]+", "<a href=\"$&\">$&</a>", RegexOptions.Compiled );
            s = Regex.Replace( s, "[0-9a-zA-Z.!#$%*/?|^{}`~&'+-=_][email protected][0-9a-zA-Z-.]+", "<a href=\"mailto:$&\">$&</a>", RegexOptions.Compiled );

            s += "</pre>";

            return s;
        }
开发者ID:bcse,项目名称:bbs2html,代码行数:41,代码来源:Form1.cs

示例12: parseDate

        /// <summary>
        ///     Parse a rfc 2822 date and time specification. rfc 2822 section 3.3
        /// </summary>
        /// <param name="date">rfc 2822 date-time</param>
        /// <returns>A <see cref="System.DateTime" /> from the parsed header body</returns>
        public static DateTime parseDate( String date )
        {
            if ( date==null || date.Equals(String.Empty) )
                return DateTime.MinValue;
            DateTime msgDateTime;
            date = SharpMimeTools.SharpMimeTools.uncommentString (date);
            msgDateTime = new DateTime (0);
            try {
                // TODO: Complete the list
                date = date.Replace("UT", "+0000");
                date = date.Replace("GMT", "+0000");
                date = date.Replace("EDT", "-0400");
                date = date.Replace("EST", "-0500");
                date = date.Replace("CDT", "-0500");
                date = date.Replace("MDT", "-0600");
                date = date.Replace("MST", "-0600");
                date = date.Replace("EST", "-0700");
                date = date.Replace("PDT", "-0700");
                date = date.Replace("PST", "-0800");

                date = date.Replace("AM", String.Empty);
                date = date.Replace("PM", String.Empty);
                int rpos = date.LastIndexOfAny(new Char[]{' ', '\t'});
                if (rpos>0 && rpos != date.Length - 6)
                    date = date.Substring(0, rpos + 1) + "-0000";
                date = date.Insert(date.Length-2, ":");
                msgDateTime = DateTime.ParseExact(date,
                    _date_formats,
                    CultureInfo.CreateSpecificCulture("en-us"),
                    DateTimeStyles.AllowInnerWhite);
            #if LOG
            } catch ( System.Exception e ) {
                if ( log.IsErrorEnabled )
                    log.Error(System.String.Concat("Error parsing date: [", date, "]"), e);
            #else
            } catch ( Exception ) {
            #endif
                msgDateTime = new DateTime (0);
            }
            return msgDateTime;
        }
开发者ID:jspraul,项目名称:pop3pipe,代码行数:46,代码来源:SharpMimeTools.cs

示例13: parseLine

        private void parseLine(String parsedLine)
        {
            if (modeCountOnly)
            {
                if (parsedLine.StartsWith("  ") && parsedLine.Length != 2) numTests++;
            }
            else
            {
                if (TEST_START.IsMatch(parsedLine))
                {
                    currentTestName = TEST_START.Match(parsedLine).Groups[1].Value;
                    potentialErrorText = "";
                }
                else if (currentTestName != null)
                {
                    if (parsedLine.StartsWith("[       OK ] " + currentTestName))
                    {
                        notifyTestComplete(currentTestName, null);
                        currentTestName = null;
                    }
                    else if (parsedLine.StartsWith("[  FAILED  ] " + currentTestName))
                    {
                        notifyTestComplete(currentTestName, potentialErrorText);
                        currentTestName = null;
                    }
                    else if (!parsedLine.StartsWith("["))
                    {
                        int errorStringIndex = parsedLine.IndexOf(": error:");
                        if (errorStringIndex != -1)
                        {
                            int errorStringStartsAt = errorStringIndex + 8;
                            parsedLine = parsedLine.Remove(errorStringStartsAt, 1);
                            parsedLine = parsedLine.Insert(errorStringStartsAt, "\r\n");
                        }
                        potentialErrorText += parsedLine + "\r\n";
                    }
                }
            }

        }
开发者ID:YangAlbert,项目名称:gtest-gbar,代码行数:40,代码来源:GoogleTestOutputParser.cs

示例14: RSA_SendString

        public void RSA_SendString(String _TxData)
        {
            //Pad the string length with whitespace to make a size evenly divisible into blocks:
            int toAdd = _TxData.Length % BlockSize;
            for(int i = 0; i < toAdd; i++)
            {
                _TxData = _TxData.Insert(_TxData.Length, " ");
            }

            //Figure out how many blocks need to be transmitted:
            int numBlocks = _TxData.Length / BlockSize;

            //Start the message transmit:
            m_CommStack.StartEncryptedMessage(numBlocks);

            //Encrypt the blocks and dump into the output stream:
            for (int i = 0; i < numBlocks; i++)
            {
                char[] temp = _TxData.ToCharArray(i * BlockSize, BlockSize);
                byte[] bytes = new byte[BlockSize];

                int j = 0;
                foreach (char c in temp)
                {
                    bytes[j++] = Convert.ToByte(c);
                }

                byte[] encrypted = m_RSAEncryptSvc.Encrypt(bytes, false);

                //Transmit the encrypted block.
                m_CommStack.TransmitEncryptedBlock(BlockSize, encrypted);
            }

            //Transmit end encrypted message
            m_CommStack.EndEncryptedMessage();
        }
开发者ID:RandomCarnie,项目名称:Project,代码行数:36,代码来源:Encryption.cs

示例15: AddMarkOfTheWeb

        public static string AddMarkOfTheWeb(String html, String webUrl)
        {
            Regex docType = new Regex("<!DOCTYPE[^>]*>");
            Regex savedFrom = new Regex("<!-- saved from url.* -->");

            //remove the existing savedFrom
            Match m = savedFrom.Match(html);
            if (m.Success)
            {
                html = html.Remove(m.Index, m.Length);
            }

            int markOffset = 0;
            m = docType.Match(html);
            if (m.Success && html.Substring(0, m.Index).Trim() == String.Empty)
            {
                markOffset = m.Index + m.Length;
            }

            String markOfTheWeb = UrlHelper.GetSavedFromString(webUrl);
            html = html.Insert(markOffset, markOfTheWeb);

            if (markOffset == 0)
            {
                //prepend a default docType declaration (fixes bug 487389)
                html = DEFAULT_MOTW_DOCTYPE + "\r\n" + html;
            }

            return html;
        }
开发者ID:gmilazzoitag,项目名称:OpenLiveWriter,代码行数:30,代码来源:HTMLDocumentHelper.cs


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