Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Carriage return characters and strings...

Status
Not open for further replies.

cerebalbore

Technical User
Mar 17, 2008
24
0
0
GB
Hi all,

I've got an issue with an application and carriage return characters, and after researching and Googling haven't found a solution.

In the application a user enters the first comment, then when a subsequent comment is added to the existing, the existing comment(string) is separated using string split on chr(10), the second comment is added and a separator is entered as chr(10) between them, and so on.

This should eventually build up a string like this:

"[1]:Blah Blah blah" & chr(10) & "[2]:blah blah blah" & chr(10) & "[3]:Blah blah blah"

This does two things - allows the datagrid view to structure each comment on separate lines and gives us a character to separate the comments from the string, which allows us to build functionality to amend comments.

The problem comes when a user presses the enter key when entering a comment. It adds VbCrLf on the end of each line, so the string eventually looks like this:

"[1]:Blah " & chr(10) & chr(13) & "blah blah" & chr(10) & "[3]:Blah blah" & chr(10)

Notice how the comments aren't in order?? And how it's almost impossible to split this string into the original comments?

So I guess my question is, is there a character I can use that will act like a carriage return (which isn't 13 or 10), and that can't be entered via the keyboard?


I'm such a noob
 

If the items ([1], [2], etc.) are being entered in a textbox, you can disable the Enter key for that textbox so users can't insert a vbCrLf. You would use the textbox's KeyDown event:

Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = Keys.Enter Then
e.Handled = True 'handle the Enter key. It won't produce a vbCrLf in the textbox
Else
'do something
End If
End Sub



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
You could also just strip out the chr(13)from your string when are retrieving the data from the textbox

dim tempstring as string = textbox.text.replace(chr(13),"")
or something like that as i haven't tested it out yet.

To go where no programmer has gone before.
 
Hi guys,

Thanks for the suggestions, I have tried to stop the users pressing enter, but they had a paddy about it.

I'll just make them choose whether they want to edit comments or press enter!!

Thanks

I'm such a noob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top