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


C# StringBuilder.Replace方法代码示例

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


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

示例1: Replace

 private static void Replace(StringBuilder str)
 {
     str.Replace("<a href=\"", "[URL=");
     str.Replace("\">","]");
     str.Replace("</a>", "[/URL]");
     Console.WriteLine(str.ToString());
 }
开发者ID:Bvaptsarov,项目名称:Homework,代码行数:7,代码来源:Program.cs

示例2: Main

    static void Main()
    {
        StringBuilder hay = new StringBuilder();

        for (int line = 0; line < 4; line++)
        {
            hay.Append(Console.ReadLine().Trim());
            hay.Append("\r\n");
        }

        string small = @">{1}-{5}>{1}";
        string medium = @">{2}-{5}>{1}";
        string large = @">{3}-{5}>{2}";

        int largeCount = Regex.Matches(hay.ToString(), large).Count;
        hay.Replace(">>>----->>", " ");
        int mediumCount = Regex.Matches(hay.ToString(), medium).Count;
        hay.Replace(">>----->", " ");
        int smallCount = Regex.Matches(hay.ToString(), small).Count;

        string decimalCount = "" + smallCount + mediumCount + largeCount;
        string binaryCount = Convert.ToString(int.Parse(decimalCount), 2);
        string binaryReversed = string.Join("", binaryCount.ToCharArray().Reverse());
        string binary = binaryCount + binaryReversed;

        Console.WriteLine(Convert.ToInt32(binary, 2));
    }
开发者ID:RandallDelat,项目名称:01_Fundamentals,代码行数:27,代码来源:LittleJohn.cs

示例3: GetRelativePath

    /// <summary>
    /// Turns the given full path into a relative one starting just above the given directory.
    /// For example, "GetRelativePath("C:/A/B/C", "B")" returns "B/C".
    /// Returns "null" if the given folder can't be found.
    /// </summary>
    /// <remarks>
    /// As a side effect, all '/' or '\' slashes will be changed
    /// to the correct directory separator char for this platform.
    /// </remarks>
    /// <param name="startFolder">
    /// The folder that will appear at the top of the returned path.
    /// </param>
    public static string GetRelativePath(string fullPath, string startFolder)
    {
        StringBuilder sb = new StringBuilder(fullPath);
        if ('/' != Path.DirectorySeparatorChar)
        {
            sb.Replace('/', Path.DirectorySeparatorChar);
        }
        if ('\\' != Path.DirectorySeparatorChar)
        {
            sb.Replace('\\', Path.DirectorySeparatorChar);
        }

        //Get the start of the given folder in the path string.
        int folderLoc = sb.ToString().IndexOf(Path.DirectorySeparatorChar +
                                              startFolder +
                                              Path.DirectorySeparatorChar);
        if (folderLoc < 0 && sb.ToString().StartsWith(startFolder + Path.DirectorySeparatorChar))
        {
            folderLoc = 0;
        }

        //If the given folder was found, cut out everything before that.
        if (folderLoc >= 0)
        {
            sb.Remove(0, folderLoc);
            if (sb[0] == Path.DirectorySeparatorChar)
                sb.Remove(0, 1);
            return sb.ToString();
        }
        else
        {
            return null;
        }
    }
开发者ID:heyx3,项目名称:GPUNoiseForUnity,代码行数:46,代码来源:StringUtils.cs

示例4: bt_Export_Click

    protected void bt_Export_Click(object sender, EventArgs e)
    {
        BindGrid(true, false);

        string filename = HttpUtility.UrlEncode(Encoding.UTF8.GetBytes(lb_ReportTitle.Text.Trim() == "" ? "Export" : lb_ReportTitle.Text.Trim()));
        Response.Charset = "UTF-8";
        Response.ContentEncoding = System.Text.Encoding.UTF8;
        Response.ContentType = "application/ms-excel";
        Response.AppendHeader("Content-Disposition", "attachment;filename=" + filename + ".xls");
        Page.EnableViewState = false;

        StringWriter tw = new System.IO.StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(tw);
        GridView1.RenderControl(hw);

        try
        {
            string tmp0 = "<tr align=\"left\" valign=\"middle\" OnMouseOver=\"this.style.cursor='hand';this.originalcolor=this.style.backgroundColor;this.style.backgroundColor='#FFCC66';\" OnMouseOut=\"this.style.backgroundColor=this.originalcolor;\" style=\"height:18px;\">";
            string tmp1 = "<tr align=\"left\" valign=\"middle\" OnMouseOver=\"this.style.cursor='hand';this.originalcolor=this.style.backgroundColor;this.style.backgroundColor='#FFCC66';\" OnMouseOut=\"this.style.backgroundColor=this.originalcolor;\" style=\"background-color:White;height:18px;\">";
            StringBuilder outhtml = new StringBuilder(tw.ToString());
            outhtml = outhtml.Replace(tmp0, "<tr>");
            outhtml = outhtml.Replace(tmp1, "<tr>");
            outhtml = outhtml.Replace("&nbsp;", "");

            Response.Write(outhtml.ToString());
        }
        catch
        {
            Response.Write(tw.ToString());
        }
        Response.End();

        BindGrid(false, false);
    }
开发者ID:fuhongliang,项目名称:GraduateProject,代码行数:34,代码来源:ReportViewer.aspx.cs

示例5: Main

    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int step = int.Parse(Console.ReadLine());

        StringBuilder bits = new StringBuilder();

        for (int i = 0; i < n; i++)
        {
            int num = int.Parse(Console.ReadLine());
            string currentLineBits = Convert.ToString(num, 2).PadLeft(8, '0');
            bits.Append(currentLineBits);
        }

        for (int i = 0; i < bits.Length; i+=step)
        {
            char currentDigit = bits[i];

            if (currentDigit == '0')
            {
                bits.Replace('0', '1', i, 1);
            }
            else
            {
                bits.Replace('1', '0', i, 1);
            }
        }

        for (int i = 0; i < bits.Length; i+=8)
        {
            string current = bits.ToString().Substring(i, 8);
            int num = Convert.ToInt32(current, 2);
            Console.WriteLine(num);
        }
    }
开发者ID:vanncho,项目名称:SoftUni-Entrance-Exam-Prepare,代码行数:35,代码来源:BitsInverter.cs

示例6: ExtractHTMLBody

    static void ExtractHTMLBody(string input)
    {
        StringBuilder bodyText = new StringBuilder();
        int textStart = 0;
        for (int i = textStart; i < input.Length - 1; i++)
        {
            if (input[i] == '<' || (input[i] == '<' && input[i + 1] == '/'))
            {
                while (input[i] != '>')
                {
                    i++;
                }
            }
            else
            {
                bodyText.Append(input[i]);
            }

            if (input[i] != '>' && input[i + 1] == '<')
            {
                bodyText.Append("\n");
            }
        }
        bodyText.Replace("\r\n", " ");
        bodyText.Replace("   ", " ").Replace("  ", " ");
        bodyText.Replace("   ", " ").Replace("  ", " ");

        Console.WriteLine("{0}", bodyText);
    }
开发者ID:IvanPanchev,项目名称:TelerikAcademy,代码行数:29,代码来源:ExtractTextFromXML.cs

示例7: Main

 static void Main()
 {
     byte n = byte.Parse(Console.ReadLine());
     StringBuilder carpet = new StringBuilder();
     carpet.Capacity = n + 2;
     carpet.Append('.', n/2 - 1);
     carpet.Append("/\\");
     carpet.Append('.', n/2 - 1);
     Console.WriteLine(carpet);
     for (byte i = 0; i < n/2 - 1; i++)
     {
         if((i & 1) == 0)
         {
             carpet.Insert(n/2, "  ");
         }
         else
         {
             carpet.Insert(n/2, "/\\");
         }
         carpet.Remove(n + 1, 1);
         carpet.Remove(0, 1);
         Console.WriteLine(carpet);
     }
     carpet.Replace('/','\\', 0, n/2);
     carpet.Replace('\\','/', n/2, n/2);
     Console.WriteLine(carpet);
     for (byte i = 0; i < n / 2 - 1; i++)
     {
         carpet.Remove(n / 2 - 1, 2);
         carpet.Append('.', 1);
         carpet.Insert(0, '.');
         Console.WriteLine(carpet);
     }
 }
开发者ID:kalinalazarova1,项目名称:TelerikAcademy,代码行数:34,代码来源:Carpets.cs

示例8: Main

    static void Main()
    {
        StreamReader reader = new StreamReader(@"..\..\text.txt");
        StringBuilder result = new StringBuilder();

        using (reader)
        {
            string line = reader.ReadLine();

            while ( line != null)
            {
                StringBuilder lineToResult = new StringBuilder();
                lineToResult.Append(line);

                int wordIndex = line.IndexOf("start");

                if (wordIndex == -1)
                {
                    line = reader.ReadLine();
                    continue;
                }
                else
                {
                    while (wordIndex != -1)
                    {
                        if (IsPossibleIndex(wordIndex - 1, line.Length) && IsPossibleIndex(wordIndex + 5, line.Length))
                        {
                            if (char.IsLetter(line[wordIndex - 1]) == false && char.IsLetter(line[wordIndex + 5]) == false)
                            {
                                lineToResult.Replace("start", "finish", wordIndex, 7);
                            }
                        }
                        else if (IsPossibleIndex(wordIndex - 1, line.Length))
                        {
                            if (char.IsLetter(line[wordIndex - 1]) == false)
                            {
                                lineToResult.Replace("start", "finish", wordIndex, 6);
                            }
                        }
                        else if (IsPossibleIndex(wordIndex + 5, line.Length))
                        {
                            if (char.IsLetter(line[wordIndex + 5]) == false)
                            {
                                lineToResult.Replace("start", "finish", wordIndex, 6);
                            }
                        }
                        wordIndex = line.IndexOf("start", wordIndex + 4);
                    }
                    result.AppendLine(lineToResult.ToString());
                }
                line = reader.ReadLine();
            }

            StreamWriter writer = new StreamWriter(@"..\..\result.txt");
            using (writer)
            {
                writer.Write(result.ToString());
            }
        }
    }
开发者ID:jesusico83,项目名称:Telerik,代码行数:60,代码来源:WholeWordsReplacement.cs

示例9: Main

    static void Main()
    {
        StringBuilder sb = new StringBuilder();

        sb.Append(Console.ReadLine());

        sb.Replace("-", "");
        sb.Replace(",", "");
        sb.Replace(".", "");

        BigInteger sum = 0;

        do
        {
            sum = 0;
            for (int i = 0; i < sb.Length; i++)
            {
                sum += (BigInteger)Char.GetNumericValue(sb[i]);
            }
            sb.Clear();
            sb.Append(sum);
        } while (sum > 9);

        Console.WriteLine(sum);
    }
开发者ID:NikolaPineda,项目名称:Telerik,代码行数:25,代码来源:AstrologicalDigits.cs

示例10: InjectSVGViewer

    public static bool InjectSVGViewer(string SVGPath, string virtualRoot)
    {
        try
        {
            if (System.IO.File.Exists(SVGPath))
            {
                StringBuilder contents = null;
                using (StreamReader sr = new StreamReader(SVGPath))
                {
                    contents = new StringBuilder(sr.ReadToEnd());
                }

                System.IO.File.Delete(SVGPath);

                string searchfor = "http://www.w3.org/1999/xlink\">";
                contents.Replace(searchfor, "http://www.w3.org/1999/xlink\" onload=\"init(evt)\" >");

                searchfor = "</svg>";
                contents.Replace(searchfor, "<script xlink:href=\"" + virtualRoot + "/Scripts/SVGzoom.js\"/>\n<script xlink:href=\"" + virtualRoot + "/Scripts/effect.js\"/>\n" + searchfor);

                using (StreamWriter sw = new StreamWriter(SVGPath, false, Encoding.Default, contents.Length))
                {
                    sw.Write(contents.ToString());
                    sw.Close();
                }
            }

        }
        catch (Exception e)
        {
            return false;
        }

        return true;
    }
开发者ID:abordt,项目名称:Viking,代码行数:35,代码来源:SVG.cs

示例11: Main

 static void Main()
 {
     int numLines = int.Parse(Console.ReadLine());
     string indentation = Console.ReadLine();
     StringBuilder sb = new StringBuilder();
     for (int i = 0; i < numLines; i++)
     {
         if (i > 0) sb.Append(Environment.NewLine);
         sb.Append(Console.ReadLine());
     }
     sb.Replace("{", Environment.NewLine + "{" + Environment.NewLine);
     sb.Replace("}", Environment.NewLine + "}" + Environment.NewLine);
     int sbLen = 0;
     do
     {
         sbLen = sb.Length;
         sb.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine);
         sb.Replace("  "," ");
     } while (sbLen != sb.Length);
     string[] lines = sb.ToString().Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
     string indent = "";
     for (int i = 0; i < lines.Length; i++)
     {
         lines[i] = lines[i].Trim();
         if (lines[i] == "") continue;
         if (lines[i] == "}")
             indent = indent.Remove(0, indentation.Length);
         Console.Write(indent);
         Console.WriteLine(lines[i]);
         if (lines[i] == "{")
             indent = indent + indentation;
     }
 }
开发者ID:TheOldMan66,项目名称:TelerikAcademy,代码行数:33,代码来源:Brackets.cs

示例12: FixDirectorySeparators

 /// <summary>
 /// Replaces all directory separators with the correct one for the current platform (either / or \).
 /// </summary>
 public static string FixDirectorySeparators(string path)
 {
     StringBuilder sb = new StringBuilder(path);
     sb.Replace('/', Path.DirectorySeparatorChar);
     sb.Replace('\\', Path.DirectorySeparatorChar);
     return sb.ToString();
 }
开发者ID:heyx3,项目名称:GPUNoiseForUnity,代码行数:10,代码来源:StringUtils.cs

示例13: GetRelativePath

	/// <summary>
	/// Turns the given full path into a relative one starting just above the given directory.
	/// For example, "GetRelativePath("C:/A/B/C", "B")" returns "B/C".
	/// Returns "null" if the given folder can't be found.
	/// </summary>
	/// <remarks>
	/// As a side effect, all '/' or '\' slashes will be changed
	/// to the correct directory separator char for this platform.
	/// </remarks>
	/// <param name="startFolder">
	/// The folder that will appear at the top of the returned path.
	/// </param>
	public static string GetRelativePath(string fullPath, string startFolder)
	{
		StringBuilder sb = new StringBuilder(fullPath);
		if ('/' != Path.DirectorySeparatorChar)
		{
			sb.Replace('/', Path.DirectorySeparatorChar);
		}
		if ('\\' != Path.DirectorySeparatorChar)
		{
			sb.Replace('\\', Path.DirectorySeparatorChar);
		}
		
		int folderLoc = sb.ToString().IndexOf(Path.DirectorySeparatorChar +
											  startFolder +
											  Path.DirectorySeparatorChar);
		if (folderLoc >= 0)
		{
			sb.Remove(0, folderLoc);
			if (sb[0] == Path.DirectorySeparatorChar)
				sb.Remove(0, 1);
			return sb.ToString();
		}
		else
		{
			return null;
		}
	}
开发者ID:heyx3,项目名称:TreeGen,代码行数:39,代码来源:PathUtils.cs

示例14: Main

    static void Main()
    {
        int number = int.Parse(Console.ReadLine());

        List<int> bitsPositions = new List<int>();
        List<string> commands = new List<string>();

        while (true)
        {
            string bitPos = Console.ReadLine();

            if (bitPos == "quit")
            {
                break;
            }

            bitsPositions.Add(int.Parse(bitPos));

            string command = Console.ReadLine();
            commands.Add(command);
        }

        StringBuilder manipulate = new StringBuilder();
        string numberAsBits = Convert.ToString(number, 2).PadLeft(32, '0');
        manipulate.Append(numberAsBits);

        for (int i = 0; i < commands.Count; i++)
        {
            string currentCommand = commands[i];
            int pos = 31 - bitsPositions[i];

            switch (currentCommand)
            {
                case "flip":
                    if (manipulate[pos] == '0')
                    {
                        manipulate.Replace('0', '1', pos, 1);
                    }
                    else
                    {
                        manipulate.Replace('1', '0', pos, 1);
                    }
                    break;
                case "remove":
                    manipulate.Remove(pos, 1);
                    manipulate.Insert(0, '0');
                    break;
                case "insert":
                    manipulate.Remove(0, 1);
                    manipulate.Insert(pos, '1');
                    break;
            }
        }

        ulong result = Convert.ToUInt64(manipulate.ToString(), 2);
        Console.WriteLine(result);
    }
开发者ID:vanncho,项目名称:SoftUni-Entrance-Exam-Prepare,代码行数:57,代码来源:BitBuilder.cs

示例15: TagReplacer

    private static void TagReplacer(string text)
    {
        StringBuilder builder = new StringBuilder(text);

        builder.Replace("<a href=\"", "[URL=");
        builder.Replace("\">", "]");
        builder.Replace("</a>", "[/URL]");
        Console.WriteLine(builder);
    }
开发者ID:radenkovn,项目名称:Telerik-Homework,代码行数:9,代码来源:ReplaceTags.cs


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