Thursday, December 4, 2008

Newline codes in Notes documents

If you write this value to a Notes document:
"Hello" & Chr( 10 ) & "World"
Notes will automatically convert the Chr( 10 ) to a full 2 bytes newline: Chr( 13 ) & Chr( 10 )

Don't know if this is good or bad - but it took me some time to figure out why the strings on my document was changed...
Sample code:


Dim session As New NotesSession
Dim doc As NotesDocument
Set doc = session.CurrentDatabase.CreateDocument
Dim s As String
s = "Hello" & Chr( 10 ) & "World" 'Use Chr( 13 ) & Chr( 10 ) instead
doc.string = "Hello" & Chr( 10 ) & "World"
If doc.string( 0 ) <> s Then
Print "Not has auto converted Chr( 10 ) to Chr( 13 ) & Chr( 10 )"
End If

1 comments:

Finn L. Knudsen said...

It has to do with how data is stored in a Notes Item.
Internal a newline is stored as Ascii 0x00, and then when you read the data it is translated into newline for the platform you are running on.
Unix and Linux: \n, 10
Windows: \r\n, 13 + 10

 
Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License.