PowerBuilder
PowerBuilder
Get an Attachment as Text with CRLF Line Endings
See more Email Object Examples
Demonstrates the Chilkat Email.GetAttachmentStringCrLf method, which retrieves an attachment's data as text with all end-of-line sequences translated to CRLF (\r\n). The first argument is the zero-based attachment index and the second is the charset used to interpret the bytes. This example reads a text attachment and normalizes its line endings to CRLF.
Background: Different systems mark the end of a line differently — Unix uses a single
LF (\n), classic Mac used CR, and Windows/most internet protocols use CRLF (\r\n). Text pulled from an attachment can contain any of these. This method normalizes them all to CRLF, which is convenient when the text will be written to a protocol or format that expects consistent CRLF line endings, avoiding mixed-newline surprises.Chilkat PowerBuilder Downloads
integer li_rc
oleobject loo_Email
string ls_Content
// Demonstrates the GetAttachmentStringCrLf method, which retrieves an attachment's data as
// text with all end-of-line sequences translated to CRLF. The first argument is the
// zero-based attachment index and the second is the charset used to interpret the bytes.
loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")
if li_rc < 0 then
destroy loo_Email
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Email.Subject = "Attachment as text (CRLF)"
loo_Email.AddStringAttachment("notes.txt","Line one.~nLine two.~nLine three.")
// Get the first attachment (index 0) as text with CRLF line endings.
ls_Content = loo_Email.GetAttachmentStringCrLf(0,"utf-8")
Write-Debug "Attachment 0 text (CRLF-normalized):"
Write-Debug ls_Content
destroy loo_Email