How can I replace the newline character with something else from a textbox?

In my database I have addresses in one line, comma separated. That way they can be as many lines as they want...

I read from the database and put addresses in a textbox as you would like to read them - on individual lines. I use a simple string substitution:
txtAddress.Text = Replace(cmbAddress.Text, ",", vbNewLine)

I'm having problems saving it back to the database with commas if the user modifies it. I tried variations on:
Replace(txtAddress.Text, vbNewLine, ",")
with vbCrLf or chr(13) isntead of vbNewLine with no success so far...

Anyone know how I can succesfully find my new line characters and replace them with commas

Thanks,

James


Answer this question

How can I replace the newline character with something else from a textbox?

  • Sarguna

    It was a silly mistake on my part. I am converting the text in several places and I wasn't doing it in one of the key areas. I am succesfully using:
    Replace(txtAddress.Text, vbCrLf, ",")

  • Paul Bradley

    I am having the same problem all i have in my code is the following

    Dim ws As StreamWriter = New StreamWriter(filename)
    Dim str As String
    str = TextBox1.Text
    Replace(str, chr(13), "|")
    ws.WriteLine(str)
    ws.Close()

    I have tried chr(13), vbNewLine, vbCrLf, environment.newline. Nothing is working. I also tried the unicode way Replace(str, 13, "|"c).

    Any help would be great thanks.

  • Xelestial

    have you tried:

    Dim replacedString as String = txtAddress.Text

    replacedString = replacedString.Replace(Environment.NewLine, ",")



  • SQLChamp

    Not sure without trying it but does the replace function call affect the string it's reading Try str = Replace(str, chr(13), "|") or str = Replace(TextBox1.Text, chr(13), "|")
  • Luo Cao

    You're a genius. It works great.

    str = replace(str, chr(13) & chr(10), "|")

    I also found out that chr(10) is needed to replace the line feed

    thanks for the help

  • How can I replace the newline character with something else from a textbox?