Results 1 to 10 of 10

Thread: [2005] Why? (Replace text problem)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2007
    Posts
    87

    [2005] Why? (Replace text problem)

    I am making/remaking a mail program i wrote quite some time ago.
    It directly inserted HTML on the place it was needed what made quite a mess inside the textbox.

    Now i wanna do this afterwards to replace things like [-B] TEXT [-/B] with html code so it wont mess up my text.
    How ever i wanna do this with 'enters' too but that is where the problem starts.

    If i put this code on the keyPressed event then it works all fine(remember Keys.ENTER is equel to 13(enum code)):

    Code:
     If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Enter) Then
                Console.WriteLine("enterpressed")
            End If
    It shows inside the output when i press enter.

    BUT BUT BUT when i try to search to those 'enters' i just cant find them.
    This is the code i have:

    Code:
    For Each s As Char In txtRich.Text.ToCharArray
    
                If s = ChrW(Keys.Enter) Then
                    Console.WriteLine("Enter found")
    
                End If
    
    
            Next
    it just dont find it.
    And i have no idea why :S.

    I made it work with comparing the hashcode(after printing the hashcode of the enter char to the output and copy it) but with that cant preform replacements in a string like this:

    Code:
    contentToSend = txtRich.Text.Replace(ChrW(13), "<br>")
    Wich obviously dont work either.
    (on all code samples i tried the normal chr(13) too.)

    I hope someone can come with a solution and maybe wanna tell why i cant do this .

    Greets

  2. #2
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: [2005] Why? (Replace text problem)

    You can't search for a Keyboard key as a character. Look for Environment.NewLine instead.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2007
    Posts
    87

    Re: [2005] Why? (Replace text problem)

    I tried :

    vb Code:
    1. txtRich.Text.Replace(Environment.NewLine, "<br>")



    wich still doenst work.

    Greets


    PS i work with a rich textbox but i guess this should not make a difference to the .text property

  4. #4
    Frenzied Member
    Join Date
    Dec 2007
    Posts
    1,072

    Re: [2005] Why? (Replace text problem)

    Try searching for vbNewLine instead of "<br>"

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2007
    Posts
    87

    Re: [2005] Why? (Replace text problem)

    I wasnt looking for "<br>" but replacing with.
    vbNewLine doenst work either when i place it on the same place as Environment.NewLine.


    Greets

  6. #6
    Frenzied Member
    Join Date
    Dec 2007
    Posts
    1,072

    Re: [2005] Why? (Replace text problem)

    Why don't you use Strings.Replace$?

  7. #7

    Thread Starter
    Lively Member
    Join Date
    May 2007
    Posts
    87

    Re: [2005] Why? (Replace text problem)

    I am useing that.
    the property .text is a string

    Greets

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] Why? (Replace text problem)

    Environment.NewLine is a String that contains a standard line break for the current enviroment. On a Windows system that is a carriage return ('\r', Chr(13), ControlChars.Cr) and a line feed ('\n', Chr(10), ControlChars.Lf). If your text doesn't contain those characters then your replacement won't work. These days Windows also understands just line feeds on their own, which is the standard line break on Unix-based systems. Have you checked what your text actually contains? If Environment.NewLine isn't working then it's likely that your text contains Unix line breaks, so try replacing ControlChars.Lf instead.

    Also, it would be more correct to replace with the XHTML-compliant "<br />".
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Lively Member
    Join Date
    May 2007
    Posts
    87

    Re: [2005] Why? (Replace text problem)

    Thnx jmcil ControlChars.Lf (or chrw(10)) works .

    Ty

    Greets

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] Why? (Replace text problem)

    Use ControlChars.Lf.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width