CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Aug 2001
    Posts
    16

    Removing Carrage Returns

    Hi There,

    I have a control that has a text box that allows users to enter text. How do I delete/remove the carriage returns if the users did not enter any text and hit the carriage return key on the keyboard a few times.

    Thanks in Advance

    Beth


  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Removing Carrage Returns

    Replace function very useful when I want to avoid too many append operations just to insert
    non-printable characters.


    Replace(Text1,vbCrLf,"")

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  3. #3
    Join Date
    Aug 2001
    Posts
    16

    Re: Removing Carrage Returns

    I need to search for lines that only has vbCrLf and remove them, but leaving those lines that containing text.


  4. #4
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Removing Carrage Returns

    Check the length of the line. If len(line) = 0 then remove vbcrlf

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  5. #5
    Join Date
    Aug 2001
    Posts
    16

    Re: Removing Carrage Returns

    Sorry, I'm very new to VB Programming. Is there a function for remove vbCrLf as you mentioned

    Thanks for all your help


  6. #6
    Join Date
    Aug 2001
    Posts
    16

    Re: Removing Carrage Returns

    Here is my code

    If Len(ctlTextBox.Text) = 0 Then
    ctlTextBox.Text = ""
    Else
    ctlTextBox.Text=ctlTextBox.Text & vbCrLf
    End if

    If I hit the return key a few time on my keyboard in the text box. ctlTextBox.Text gives me "llll"(not exactly as shown, it more vertical barcode marks in bold). It is indicating it is not 0.

    Appreciate your help.

    Beth


  7. #7
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Removing Carrage Returns

    Your code is not going to do anything but add the vbcrlf at the end of the text box.
    What you have to do is read the text between the vbcrlf using InStr function. If the length of the line between vbcrlf is = 0 then replace the vbcrlf with "". Otherwise do not do anything

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  8. #8
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Removing Carrage Returns

    Replace function will substitute vbcrlf with "" (or whatever you want to)

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

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

Featured