String Functions

Does anyone know if there's a string function that removes new lines from a string (where return has been hit to start a new paragraph) It's kind of like the Trim functions I'm looking for, but these only work with trailing spaces, not where a new line has been started.

Cheers!

Keith



Answer this question

String Functions

  • tcarff

    nae bother big yin. :)

  • Nick Mc

    Hey man,

    Try the Replace() function. Just replace all the vbCrLf in the string with "" and that will remove them.



  • Leo Ng

    myString.Replace(Environment.NewLine.ToCharArray(), String.Empty.ToCharArray())


  • SQLScott

    Cheers for that. My final solution below. Basically, it's a text box where it is possible for the user to hit return and begin a new paragraph if they wish, but where I was writing that input to could not have new lines.

    Replace(Cont.Value, vbNewLine, " ")

    Cheers, guys!


  • JeremyAtGosub

    Your right. I didn't pay attention to on what forum it was:)


  • AndyB_UK_2006

    Cheers guys! I'll give it a go!
  • Nuno_Salvado

    Hi Keith

    Below example is one option to remove carriage returns (replacing with a space). Just change it to a function and pass your string to it as a parameter

    Public Sub mysub()
    Dim MyString As String
    MyString = "first line - " & Chr$(13) & "second line - " & Chr$(13) & "third line - "
    Debug.Print MyString
    While InStr(1, MyString, Chr$(13)) > 0
    Mid$(MyString, InStr(1, MyString, Chr$(13)), 1) = " "
    Wend
    Debug.Print MyString
    End Sub


  • doener

    Hi,

    I unmarked CetinBasoz post as the answer as the code given is VB.NET and not VBA.



  • String Functions