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


C# StringBuilder.Insert方法代码示例

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


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

示例1: HighlightPattern

        /// <summary>
        /// Encloses each pattern substring in the target string with highlight tag.
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="target"></param>
        /// <param name="pattern"></param>
        /// <param name="highlightTag"></param>
        /// <returns></returns>
        public static MvcHtmlString HighlightPattern(this HtmlHelper helper, string target, string pattern, string highlightTag)
        {
            // This is a dirty code which encloses with tags every pattern match .
            // And in the same time save the original case of the pattern match.
            // I know it can be achieved with one regular expression. But I don't know this expression.

            var openTag = String.Format("<{0}>", highlightTag);
            var closeTag = String.Format("</{0}>", highlightTag);
            var builder = new StringBuilder(target);

            if (!string.IsNullOrEmpty(pattern))
            {

                var match = Regex.Match(target, pattern, RegexOptions.IgnoreCase);

                int count = 0;
                while (match.Success)
                {
                    builder.Insert(match.Index + count, openTag);
                    count += openTag.Length;
                    builder.Insert(match.Index + match.Length + count, closeTag);
                    count += closeTag.Length;
                    match = match.NextMatch();
                }
            }
            return new MvcHtmlString(builder.ToString());
        }
开发者ID:pengwin,项目名称:SampleProject,代码行数:35,代码来源:HighlightPattern.cs

示例2: formatCurrencyText

        public static string formatCurrencyText(string content, string _preFix, char _thousandsSeparator, char _decimalsSeparator)
        {
            int _decimalPlaces = 0;
            int counter = 1;
            int counter2 = 0;
            char[] charArray = content.ToCharArray();
            StringBuilder str = new StringBuilder();

            for (int i = charArray.Length - 1; i >= 0; i--)
            {
                str.Insert(0, charArray.GetValue(i));
                if (_decimalPlaces == 0 && counter == 3)
                {
                    counter2 = counter;
                }

                if (counter == _decimalPlaces && i > 0)
                {
                    if (_decimalsSeparator != Char.MinValue)
                        str.Insert(0, _decimalsSeparator);
                    counter2 = counter + 3;
                }
                else if (counter == counter2 && i > 0)
                {
                    if (_thousandsSeparator != Char.MinValue)
                        str.Insert(0, _thousandsSeparator);
                    counter2 = counter + 3;
                }
                counter = ++counter;
            }
            return (_preFix != "" && str.ToString() != "") ? _preFix + " " + str.ToString() : (str.ToString() != "") ? str.ToString() : "";
        }
开发者ID:psautomationteam,项目名称:manufacturingmanager,代码行数:32,代码来源:Global.cs

示例3: AddBinary

        public string AddBinary(string a, string b)
        {
            var carry = 0;
            var builder = new StringBuilder();

            var aLength = a.Length - 1;
            var bLength = b.Length - 1;

            int aVal, bVal, val;
            while (aLength >= 0 || bLength >= 0)
            {
                aVal = aLength >= 0 ? a[aLength] - '0' : 0;
                bVal = bLength >= 0 ? b[bLength] - '0' : 0;

                val = aVal + bVal + carry;
                builder.Insert(0, val & 1);

                carry = val >> 1;

                aLength--;
                bLength--;
            }

            if (carry >= 1)
            {
                builder.Insert(0, carry);
            }

            return builder.ToString();
        }
开发者ID:BigEgg,项目名称:LeetCode,代码行数:30,代码来源:067-AddBinary.cs

示例4: Main

        static void Main()
        {
            string chochkosBulshit = Console.ReadLine();

            var ragePattern = new Regex(@"(?<rage>[^\d]{1,20})(?<count>\d{1,2})");

            var uniqueSymbols = new HashSet<char>();

            var resultBuilder = new StringBuilder();

            foreach (Match m in ragePattern.Matches(chochkosBulshit))
            {
                string rage = m.Groups["rage"].Value.ToUpper();

                int repetitions;
                int.TryParse(m.Groups["count"].Value, out repetitions);

                if (repetitions != 0)
                {
                    foreach (char c in rage)
                    {
                        uniqueSymbols.Add(c);
                    }

                    resultBuilder.Insert(resultBuilder.Length, rage, repetitions);
                }
            }

            resultBuilder.Insert(0, string.Format("Unique symbols used: {0}\n", uniqueSymbols.Count));

            Console.WriteLine(resultBuilder.ToString());
        }
开发者ID:kidroca,项目名称:Advanced-CSharp-2015,代码行数:32,代码来源:Program.cs

示例5: FindXPath

 public static string FindXPath(XmlNode node)
 {
     var builder = new StringBuilder();
     while (node != null)
     {
         switch (node.NodeType)
         {
             case XmlNodeType.Attribute:
                 builder.Insert(0, "/@" + node.Name);
                 node = ((XmlAttribute)node).OwnerElement;
                 break;
             case XmlNodeType.Element:
                 var index = FindElementIndex((XmlElement)node);
                 builder.Insert(0, "/" + node.Name + "[" + index + "]");
                 node = node.ParentNode;
                 break;
             case XmlNodeType.Document:
                 return builder.ToString();
             default:
                 throw new ArgumentException("Only elements and attributes are supported");
         }
     }
     return "*";
     //            throw new ArgumentException("Node was not in a document");
 }
开发者ID:krishachetan89,项目名称:Winium.StoreApps,代码行数:25,代码来源:XPathHelpers.cs

示例6: FromUpcA

        public static string FromUpcA(string value)
        {
            if (!Regex.IsMatch(value, @"^[01]\d{2}([012]0{4}\d{3}|[3-9]0{4}\d{2}|\d{4}0{4}\d|\d{5}0{4}[5-9])"))
                throw new ArgumentException("UPC A code cannot be compressed.");

            StringBuilder result = new StringBuilder(value);

            if (result[5] != '0')
                result.Remove(6, 4);
            else if (result[4] != '0')
            {
                result.Remove(5, 5);
                result.Insert(6, "4");
            }
            else if (result[3] != '2' && result[3] != '1' && result[3] != '0')
            {
                result.Remove(4, 5);
                result.Insert(6, "3");
            }
            else
            {
                result.Insert(11, result[3]);
                result.Remove(3, 5);
            }

            return result.ToString();
        }
开发者ID:noikiy,项目名称:Barcodes,代码行数:27,代码来源:UPCE.cs

示例7: ConvertNumberToString

        private string ConvertNumberToString(int number)
        {
            int tenPow = 1;
            StringBuilder retSb = new StringBuilder();
            do
            {
                int valueRedunt;
                int valueUnit;
                tenPow *= 10;

                valueRedunt = number % tenPow;
                valueUnit = valueRedunt / (tenPow / 10);

                retSb.Insert(0, " ");
                retSb.Insert(0, DecimalPositionalToString((DecimalPositional)tenPow));
                retSb.Insert(0, " ");
                retSb.Insert(0, valueUnit);
            }while(number/tenPow > 0);

            retSb.Insert(0, " ");
            retSb.Insert(0, "có:");
            retSb.Insert(0, " ");
            retSb.Insert(0, number);
            retSb.Insert(0, " ");
            retSb.Insert(0, "Số");

            return retSb.ToString();
        }
开发者ID:CockDeveloper,项目名称:Exercise_resolve,代码行数:28,代码来源:Ex001_InformationOfNumber.cs

示例8: ConvertShortcutToString

		public static string ConvertShortcutToString(Shortcut shortcut)
		{
			string shortcutString = Convert.ToString(shortcut);
			StringBuilder result = new StringBuilder(shortcutString);

			if (shortcutString.StartsWith("Alt"))
			{
				result.Insert(3, " + ");
			}
			else if (shortcutString.StartsWith("CtrlShift"))
			{
				result.Insert(9, " + ");
				result.Insert(4, " + ");
			}
			else if (shortcutString.StartsWith("Ctrl"))
			{
				result.Insert(4, " + ");
			}
			else if (shortcutString.StartsWith("Shift"))
			{
				result.Insert(5, " + ");
			}

			return result.ToString();
		}
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:25,代码来源:NuGenShortcutConverter.cs

示例9: ToString

        public override string ToString()
        {
            var textBuilder = new StringBuilder();

            for (int offset = 0; offset < BitCount; offset++)
            {
                int shift = BitCount - offset - 1;
                bool bitIsSet = (Value & ((ulong) 1 << shift)) != 0;
                textBuilder.Append(bitIsSet ? '1' : '0');
            }

            // Add leading zeros when not whole nibbles.
            while (textBuilder.Length % 4 != 0)
            {
                textBuilder.Insert(0, '0');
            }

            // Insert dot (.) between nibbles.
            for (int index = textBuilder.Length - 4; index > 0; index -= 4)
            {
                textBuilder.Insert(index, '.');
            }

            return textBuilder.ToString();
        }
开发者ID:bkoelman,项目名称:DogAgilityCompetitionManagement,代码行数:25,代码来源:OrderingScenario.cs

示例10: flareOut

 public string[] flareOut(string[] snowflake)
 {
     string[] temp = new string[snowflake.Length];
     for (int i = 0; i < snowflake[snowflake.Length - 1].Length; i++)
     {
         StringBuilder sb = new StringBuilder();
         for (int a = snowflake.Length - 1; a > i; a--)
         {
             sb.Insert(0, snowflake[a][i].ToString());
         }
         if (sb.ToString() == "")
             temp[i] = snowflake[i];
         else
         {
             sb.Insert(0, snowflake[i]);
             temp[i] = sb.ToString();
         }
     }
     for (int i = 0; i < temp.Length; i++)
     {
         StringBuilder sb = new StringBuilder();
         for (int a = temp[i].Length - 1; a >= 0; a--)
             sb.Append(temp[i][a].ToString());
         sb.Append(temp[i]);
         temp[i] = sb.ToString();
     }
     string[] result = new string[temp.Length * 2];
     int x = -1;
     for (int i = temp.Length - 1; i >= 0; i--)
         result[++x] = temp[i];
     for (int i = 0; i < temp.Length; i++)
         result[++x] = temp[i];
     return result;
 }
开发者ID:knighthunter09,项目名称:TopBlogCoder,代码行数:34,代码来源:Program.cs

示例11: BackupViewer

        public BackupViewer(Main main)
        {
            InitializeComponent();

            _Main = main;
            this.Icon = Me.Amon.Hosts.Properties.Resources.Icon;

            if (Directory.Exists(Main.BAK_DIR))
            {
                string name;
                StringBuilder text = new StringBuilder();
                foreach (string file in Directory.GetFiles(Main.BAK_DIR, string.Format(Main.HOSTS_FILE, "*")))
                {
                    name = Path.GetFileName(file);
                    name = name.Substring(6);
                    if (name.Length != 14)
                    {
                        continue;
                    }

                    text.Append(name);
                    text.Insert(12, ':').Insert(10, ':');
                    text.Insert(8, ' ');
                    text.Insert(6, '-').Insert(4, '-');
                    LbBak.Items.Add(new KVItem { K = name, V = text.ToString() });
                    text.Clear();
                }
            }
        }
开发者ID:burstas,项目名称:rmps,代码行数:29,代码来源:BackupViewer.cs

示例12: GetDirectoryPath

        static String GetDirectoryPath(XmlNode componentNode, XmlNamespaceManager nsm)
        {
            XmlNode parent = componentNode.ParentNode;
            StringBuilder installationPath = new StringBuilder("");

            if (parent != null)
            {
                XmlAttribute id = parent.Attributes["Id"];
                string s_id = (id != null) ? id.Value : "";

                // If it is of type wix:Directory get the name or id.
                if (parent.Name == "Directory")
                {
                    installationPath.Insert(0, GetNodeDirectory(parent, nsm));
                    installationPath.Insert(0, GetDirectoryPath(parent, nsm));
                }
                // If the parent is of type wix:DirectoryRef find the wix:Directory node that the
                // DirectoryRef points to and then get the name or id.
                else if (parent.Name == "DirectoryRef")
                {
                    if (!String.IsNullOrEmpty(s_id))
                    {
                        XmlNode installdir = parent.SelectSingleNode(String.Format("//wix:Directory[@Id='{0}']", s_id), nsm);
                        if (installdir != null)
                        {
                            installationPath.Insert(0, GetNodeDirectory(installdir, nsm));
                            installationPath.Insert(0, GetDirectoryPath(installdir, nsm));
                        }
                    }
                }
            }

            return installationPath.ToString();
        }
开发者ID:stephenwelsh,项目名称:msiext,代码行数:34,代码来源:Program.cs

示例13: Main

 static void Main(string[] args)
 {
     Console.Write("Please enter signed 16bit integer: ");
     string inputStr = Console.ReadLine();
     short number = short.Parse(inputStr);
     StringBuilder result = new StringBuilder();
     if (number >= 0)
     {
         int workingNum = number;
         for (int i = 0; i < 16; i++)
         {
             int temp = workingNum % 2;
             workingNum = workingNum / 2;
             result.Insert(0, temp);
         }
     }
     else
     {
         int workingNum = Math.Abs(number) - 1;
         for (int i = 0; i < 16; i++)
         {
             int temp = workingNum % 2;
             workingNum = workingNum / 2;
             if (temp == 0)
             {
                 result.Insert(0, '1');
             }
             else
             {
                 result.Insert(0, '0');
             }
         }
     }
     Console.WriteLine("In Binary {0} equals {1}", inputStr, result.ToString());
 }
开发者ID:mitev-web,项目名称:csharp-fundamentals,代码行数:35,代码来源:ShortToBinary.cs

示例14: stringify

 private static string stringify(FbDataReader reader, string parentnodename)
 {
     StringBuilder json = new StringBuilder();
     int columns = reader.FieldCount;
     if (parentnodename.Length > 0) { json.AppendFormat("{{\"{0}\":", parentnodename); }
     while (reader.Read())
     {
         for (int i = 0; i < columns; i++)
         {
             if (i % reader.FieldCount == 0) { json.Append("{"); }
             json.AppendFormat("\"{0}\":{1},", reader.GetName(i).ToLower(), jsonify(reader.GetValue(i)));
             if (i % reader.FieldCount == reader.FieldCount - 1)
             {
                 json.Remove(json.Length - 1, 1);
                 json.Append("},");
             }
         }
     }
     // if nothing (or only the parentnodename is appended to the string builder then the reader was empty and we return nothing. reader.HasRows doesn't work
     if (json.Length == 0 || json.ToString() == string.Format("{{\"{0}\":", parentnodename)) { return ""; }
     json.Remove(json.Length - 1, 1);
     if (parentnodename.Length > 0) { json.Append("}"); }
     // check if the json should contain an array and add array structure if true
     if (Regex.IsMatch(json.ToString(), "},{"))
     {
         json.Insert((parentnodename.Length > 0 ? parentnodename.Length + 4 : 4), "[");
         json.Insert(json.Length - 1, "]");
     }
     return json.ToString();
 }
开发者ID:dotnetCarpenter,项目名称:teeboa,代码行数:30,代码来源:RoppongiMethods.cs

示例15: Encode

        private static string Encode(StringBuilder finalString)
        {
            int counterOccurance = 1;
            char ch = ' ';

            for (int i = 0; i < finalString.Length - 1; i++)
            {
                if (finalString[i] == finalString[i + 1])
                {
                    counterOccurance++;
                    ch = finalString[i];
                }

                else if (counterOccurance > 2 && counterOccurance < finalString.Length -1
                    && finalString[i] != finalString[i + 1])
                {
                    finalString.Remove(i - (counterOccurance - 1), counterOccurance);
                    finalString.Insert(i - counterOccurance + 1, counterOccurance);
                    finalString.Insert(i - (counterOccurance - counterOccurance.ToString().Length - 1), ch);

                }
                if ((i < finalString.Length - 1) && finalString[i] != finalString[i + 1])
                {
                    counterOccurance = 1;
                }

            }
            return finalString.ToString();
        }
开发者ID:Wooanna,项目名称:GitHubTelerikAcademy,代码行数:29,代码来源:EncodeAndEncrypt.cs


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