Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Regex.Replace Chr(10)

Regex.Replace Chr(10)

Scheduled Pinned Locked Moved C#
csharphelphtmlregex
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    J Liang
    wrote on last edited by
    #1

    Hi, I am stuck on this line of code from VB.NET which I am trying to convert it to C#, Dim str As String = Regex.Replace(SomeString, "
    ", Chr(10)). I'd tried ((char)10).ToString(), @"\n", Environement.NewLine, Convert.ToChar(10) but nothing helps. The 'SomeString' is suppose to be some HTML text like Home and after runnng the Regex.Replace, it is suppose to be 'Home' on 'str' where all the HTML codes are being scrap off. Hope you can help me on this. Jie Liang

    J 1 Reply Last reply
    0
    • J J Liang

      Hi, I am stuck on this line of code from VB.NET which I am trying to convert it to C#, Dim str As String = Regex.Replace(SomeString, "
      ", Chr(10)). I'd tried ((char)10).ToString(), @"\n", Environement.NewLine, Convert.ToChar(10) but nothing helps. The 'SomeString' is suppose to be some HTML text like Home and after runnng the Regex.Replace, it is suppose to be 'Home' on 'str' where all the HTML codes are being scrap off. Hope you can help me on this. Jie Liang

      J Offline
      J Offline
      John Petersen
      wrote on last edited by
      #2

      Hello To convert that to C# will result in. string str = Regex.Replace(SomeString, "
      ", "\n"); Remember to include using System.Text.RegularExpressions; in the top of the file. Kind Regards, John Petersen

      J 1 Reply Last reply
      0
      • J John Petersen

        Hello To convert that to C# will result in. string str = Regex.Replace(SomeString, "
        ", "\n"); Remember to include using System.Text.RegularExpressions; in the top of the file. Kind Regards, John Petersen

        J Offline
        J Offline
        J Liang
        wrote on last edited by
        #3

        Hi John, Thanks for the speedy reply. It doesn't really work. Let me show you more of the code. tag = new Regex("<[^>]*>", RegexOptions.IgnoreCase); <--This was suppose to help me get rid all the HTML text which it works in VB.NET and don't seems to work in C# for (counter = 0; counter <= PageText.Count - 1; counter++) { string str = Regex.Replace(PageText[counter].ToString(), "
        ", "\n"); str = tag.Replace(str, ""); str = Regex.Replace(str, " ", ""); <--By this line, all the HTML text should be alredy gone str = Regex.Replace(str, "^\\s+", ""); str = Regex.Replace(str, "\\s+$", ""); PageText[counter] = str; } So if this Notify me by e-mail if someone answers this message pass into PageText[0] and send to process, it should left only "Notify me by e-mail if someone answers this message". Hope I didn't confuse you, thanks in advance Jie Liang

        G J 2 Replies Last reply
        0
        • J J Liang

          Hi John, Thanks for the speedy reply. It doesn't really work. Let me show you more of the code. tag = new Regex("<[^>]*>", RegexOptions.IgnoreCase); <--This was suppose to help me get rid all the HTML text which it works in VB.NET and don't seems to work in C# for (counter = 0; counter <= PageText.Count - 1; counter++) { string str = Regex.Replace(PageText[counter].ToString(), "
          ", "\n"); str = tag.Replace(str, ""); str = Regex.Replace(str, " ", ""); <--By this line, all the HTML text should be alredy gone str = Regex.Replace(str, "^\\s+", ""); str = Regex.Replace(str, "\\s+$", ""); PageText[counter] = str; } So if this Notify me by e-mail if someone answers this message pass into PageText[0] and send to process, it should left only "Notify me by e-mail if someone answers this message". Hope I didn't confuse you, thanks in advance Jie Liang

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          Use the "Ignore HTML" option when you post code that inlcuded html code. Now there is a lot of the code missing, so I can't really tell what you are trying to do. Why don't you use the string.Trim method instead of inventing a new one?

          --- b { font-weight: normal; }

          1 Reply Last reply
          0
          • J J Liang

            Hi John, Thanks for the speedy reply. It doesn't really work. Let me show you more of the code. tag = new Regex("<[^>]*>", RegexOptions.IgnoreCase); <--This was suppose to help me get rid all the HTML text which it works in VB.NET and don't seems to work in C# for (counter = 0; counter <= PageText.Count - 1; counter++) { string str = Regex.Replace(PageText[counter].ToString(), "
            ", "\n"); str = tag.Replace(str, ""); str = Regex.Replace(str, " ", ""); <--By this line, all the HTML text should be alredy gone str = Regex.Replace(str, "^\\s+", ""); str = Regex.Replace(str, "\\s+$", ""); PageText[counter] = str; } So if this Notify me by e-mail if someone answers this message pass into PageText[0] and send to process, it should left only "Notify me by e-mail if someone answers this message". Hope I didn't confuse you, thanks in advance Jie Liang

            J Offline
            J Offline
            John Petersen
            wrote on last edited by
            #5

            Ok Jie Liang As guffa said, you should mark the Ignore Html option when posting code here. I tried to set up a test case which resembles your code. It works for me. I post the code here. using System; using System.Collections.Generic; using System.Text; using NUnit.Framework; using System.Text.RegularExpressions; namespace Tester { [TestFixture] public class Class1 { public string Process(string[] pageText) { Regex tag = new Regex("<[^>]*>", RegexOptions.IgnoreCase); //This was suppose to help me get rid all the HTML text which it works in VB.NET and don't seems to work in C# int counter; for (counter = 0; counter <= pageText.Length - 1; counter++) { string str = Regex.Replace(pageText[counter].ToString(), "
            ", "\n"); str = tag.Replace(str, ""); str = Regex.Replace(str, " ", ""); // By this line, all the HTML text should be alredy gone str = Regex.Replace(str, "^\\s+", ""); str = Regex.Replace(str, "\\s+$", ""); pageText[counter] = str; } return pageText[0]; } [Test] public void TestFunc() { string[] PageText = { "Notify me by e-mail if someone answers this message" }; Process(PageText); } } } The output from the Process method is "Notify me by e-mail if someone answers this message" Kind Regards, John Petersen

            J 1 Reply Last reply
            0
            • J John Petersen

              Ok Jie Liang As guffa said, you should mark the Ignore Html option when posting code here. I tried to set up a test case which resembles your code. It works for me. I post the code here. using System; using System.Collections.Generic; using System.Text; using NUnit.Framework; using System.Text.RegularExpressions; namespace Tester { [TestFixture] public class Class1 { public string Process(string[] pageText) { Regex tag = new Regex("<[^>]*>", RegexOptions.IgnoreCase); //This was suppose to help me get rid all the HTML text which it works in VB.NET and don't seems to work in C# int counter; for (counter = 0; counter <= pageText.Length - 1; counter++) { string str = Regex.Replace(pageText[counter].ToString(), "
              ", "\n"); str = tag.Replace(str, ""); str = Regex.Replace(str, " ", ""); // By this line, all the HTML text should be alredy gone str = Regex.Replace(str, "^\\s+", ""); str = Regex.Replace(str, "\\s+$", ""); pageText[counter] = str; } return pageText[0]; } [Test] public void TestFunc() { string[] PageText = { "Notify me by e-mail if someone answers this message" }; Process(PageText); } } } The output from the Process method is "Notify me by e-mail if someone answers this message" Kind Regards, John Petersen

              J Offline
              J Offline
              J Liang
              wrote on last edited by
              #6

              Hi John, Hi Guffa, Sorry bout the Ignore HTML thing, I forgot to check it when I modify my post. Yes, it works, John. After reading your post, I decided to test this small piece of code and as you said, it works. Then I realized I did not show you enough information, sorry about that. The HTML code that pass into PageText[] should be in full such as 'Hello' and not 'a href="">Hello', or else it won't digest the HTML. Now everything's fine, thanks a lot to both of you, you have been very helpful :) Jie Liang

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups