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


C# Regex.Insert方法代码示例

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


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

示例1: BeautyMyCode

        private string BeautyMyCode(string Source)
        {
            Source = RemoveStr(Source, new string[] { "\n", "\x09", "  " });
            Source = new Regex("#include <(.*?)>").Replace(Source, "$0\n");
            Source = new Regex(";").Replace(Source, "$0\n");
            Source = new Regex("{").Replace(Source, "\n$0\n");
            Source = new Regex("}").Replace(Source, "$0\n");
            int DeepCount = 0;
            for (int i = 0; i < Source.Length; i++)
            {
                if (Source[i] == '}') DeepCount--;
                else if (Source[i] == '{') DeepCount++;
                else if (Source[i]  == '\n')
                {
                    int NextNewLinePos = Source.IndexOf("\n", i + 1);
                    if (NextNewLinePos != -1)
                    {
                        Console.WriteLine(Source.Substring(i, NextNewLinePos - i));
                        if (Source.Substring(i, NextNewLinePos - i).Contains("}"))
                        {
                            Source = Source.Insert(i + 1, GetManyBlankStr(DeepCount -1));
                        }
                        else
                        {
                            Source = Source.Insert(i + 1, GetManyBlankStr(DeepCount));
                        }

                    }
                }
            }
            return (Source);
        }
开发者ID:Burste,项目名称:C-CodingStyleHacker-In-CSharp,代码行数:32,代码来源:Form1.cs

示例2: KeyDowned

		private void KeyDowned (object sender, KeyEventArgs e) {
			if (e.Key == Key.Tab && this.TxtScript.SelectionLength > 0) {
				string script = this.TxtScript.Text;
				string newScript = script;

				//how many new lines are in the selection
				int numNewLines = this.TxtScript.SelectedText.Split ('\n').Length - 1;

				//get the beginning of the first line
				int firstLineStartIndex = script.LastIndexOf ("\n", this.TxtScript.SelectionStart, this.TxtScript.SelectionStart);

				//get the end of the last line
				int lastLineEndIndex = script.IndexOf ("\n", this.TxtScript.SelectionStart + this.TxtScript.SelectionLength);

				if (firstLineStartIndex <= -1) {
					firstLineStartIndex = 0;
				}

				if (lastLineEndIndex <= -1) {
					lastLineEndIndex = script.Length;
				}

				if (Keyboard.IsKeyDown (Key.LeftShift) || Keyboard.IsKeyDown (Key.RightShift)) {
					//string interestedText = script.Substring (firstLineStartIndex, lastLineEndIndex - firstLineStartIndex);
					//string newText = interestedText;
					//string [] lines = interestedText.Split ('\n');
					
					//for (int i = 0; i < lines.Length; i++) {
						
					//	if (lines [i][0] == '\t') {
					//		lines [i] = lines [i].Substring (1);
					//	}
					//}

					//newText = string.Join ("\n", lines);
					//newScript = script.Replace (interestedText, newText);
					//this.TxtScript.Text = newScript;
				} else {
					//insert a tab after every selected newline
					newScript = new Regex ("\n").Replace (newScript, "\n\t", numNewLines, firstLineStartIndex + 1);

					//insert tab in the first line
					newScript = newScript.Insert (firstLineStartIndex + (firstLineStartIndex == 0 ? 0 : 1), "\t");

					this.TxtScript.Text = newScript;
					this.TxtScript.SelectionStart = firstLineStartIndex;
					this.TxtScript.SelectionLength = lastLineEndIndex - firstLineStartIndex + numNewLines + 1;
				}

				//cancel event
				e.Handled = true;
			}
		}
开发者ID:BenjinYap,项目名称:WinRunner,代码行数:53,代码来源:BatchShortcutWidget.xaml.cs

示例3: GetHtml

        public static string GetHtml(Parser parser)
        {
            string document = parser.GetDocument();

            StringBuilder html = new StringBuilder();

            html.Append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\r\n");
            html.Append("<html>\r\n<head>\r\n<title>Title</title>\r\n<link href=\"style.css\" rel=\"stylesheet\" type=\"text/css\">\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n</head>\r\n<body>\r\n");

            if (!parser.GetSuccess())
            {
                html.Append("<p>Errors occurred while parsing the document. Please correct these before trying to export.</p>\r\n");
            }
            else
            {
                // Convert @pageref links to actual page numbers
                document = new Regex("@pageref\\((.+?)\\)").Replace(document, "<a href='#$1' class='pageref'>this link</a>");

                // Center lines
                document = new Regex("^--\\s*(.*?)\\s*$", RegexOptions.Multiline).Replace(document, "<p style='text-align: center'>$1</p>");

                // Convert lines to paragraphs (ignoring any figures, tables, or raw html)
                MatchCollection paragraphs = new Regex("(^([^@figure\\(|^@table\\(|^\n|^#|^\\$|^\\<].+?)\n)+", RegexOptions.Multiline).Matches(document);

                for (int i = paragraphs.Count - 1; i >= 0; i--)
                {
                    Match m = paragraphs[i];

                    document = document.Remove(m.Index, m.Length);
                    document = document.Insert(m.Index, "<p>\n" + m.Groups[0].Value.ToString().Substring(0, m.Groups[0].Value.Length - 1).Replace("\n", "<br>\n") + "\n</p>\n");
                }

                // Convert lines only containing # to vertical padding paragraphs
                document = new Regex("^#\n", RegexOptions.Multiline).Replace(document, "<p><br></p>\n");

                document = ProcessChapters(document, parser.GetChapters());
                document = ProcessFigures(document, parser.GetFigures());
                document = ProcessTables(document, parser.GetTables());
                document = ProcessReferences(document, parser.GetReferences());

                html.Append(document);
            }

            html.Append("</body></html>");

            return html.ToString();
        }
开发者ID:DesktopMan,项目名称:Report-Writer,代码行数:47,代码来源:HtmlGenerator.cs


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