如何替换不可见的换行符。 [英] How to replace invisible newlines.

查看:199
本文介绍了如何替换不可见的换行符。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,这是我的第一篇文章。我使用Visual Studio 2010.



我正在制作一个程序,你以一定的格式发布大量文本,然后代码分解并保存某些区域将文本作为字符串和变量,最后将其重新粘贴为URL。



Hi everyone, this is my first post. I use Visual Studio 2010.

I'm making a program that you post a bulk of text into in a certain format, the code then breaks down and saves certain areas of text as strings and variables, and finally it re-pastes it as a URL.

        public void button1_Click(object sender, EventArgs e)
        {
            var list = textBox1.Text;
            string title = showMatch(list, @"\w+\s+\d+\s+\w+\s+\W\d\d\W\d\d\W\d\d\s\d\d\S\d\d\W\s+.+");
            string poster = showMatch(list, @"\w+\s+\d+\s+\w+\s+\W\d\d\W\d\d\W\d\d\s\d\d\S\d\d\W\s");
            textBox2.Text = @"http://websitename=" + title + "moreofwebsitename" + poster + "moreofwebsitename" + comboBox1.SelectedItem + "moreofwebsitename=" + list;
            

        }

 public string showMatch(string text, string expr)
        {
            textBox1.Text = "";
            MatchCollection mc = Regex.Matches(text, expr);
            int i = 0;
            string title = "";
            foreach (Match m in mc)
            {
                title = "\n" + @m.Groups[i].ToString();
                
            }
            return title;
        }

private void button2_Click(object sender, EventArgs e)
 {
          System.Diagnostics.Process.Start("textBox2.Text");
 }





除最后一件外,该代码还能抓住我想要的作品。变量list是输入的原始文本,也需要传送到URL。问题是大量文本被发送到没有换行符的URL(http为%0A),因此只发送第一行。没有\ n或\b字符我可以使用替换功能进行更改。



总之我需要找到一种方法来定位隐藏换行符在textBox1中转义并用%0A替换它们。



提前谢谢,我希望这是有道理的,



Wiley



The code captures the pieces I want well, apart from the final piece. The variable "list" is the original text inputted, and that also needs to be transferred to the URL. The problem is that the bulk of text is sent to the URL with no newline characters (%0A for http) and therefore only the first line is sent. There are no \n or \b characters that I can use the replace function to change.

In summary I need to find a way to locate the "hidden" newline escape characters in textBox1 and replace them with "%0A".

Thanks in advance and I hope this made sense,

Wiley

推荐答案

假设textBox1是一个多行文本框,那么试试这个:

Assuming that textBox1 is a multiline textbox, then try this:
string noHiddenLines = string.Join("%0A",textBox1.Lines);


这篇关于如何替换不可见的换行符。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆