Click here to Skip to main content
15,893,564 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

C++
        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");
 }


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
Posted

1 solution

Assuming that textBox1 is a multiline textbox, then try this:
C#
string noHiddenLines = string.Join("%0A",textBox1.Lines);
 
Share this answer
 
Comments
wiley_25 21-Feb-14 18:33pm    
Worked! Thanks.
OriginalGriff 22-Feb-14 1:43am    
You're welcome!
wiley_25 22-Feb-14 9:32am    
I'm encountering a different issue now. The captured "lines" variable that gets sent to the HTTP address sometimes has special characters in, and these cause it to open up multiple webpages and therefore not send all the text to API. Is there a character I could use in the HTTP, simular to the @ in C#, that would disregard all special characters following it?
OriginalGriff 22-Feb-14 10:16am    
Is there a good reason for using query strings?
Personally, I'd use the Session, or Cookies instead.
wiley_25 22-Feb-14 11:22am    
Mainly because I am very new to programming and I understand queries. I'm sure I'll build up to Cookies though. I made a fix, just used <pre>list = list.Replace(";", "%3B");</pre> for every character that was causing issues.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900