Today I needed to use LotusScript to find the length of a string, in bytes. It took a little experimentation, so I figured I should post it here in case anyone else might sometime find it useful. This is in LotusScript; there's probably an easier way in Java, but I needed it for a form validation.
Function LmbcsLen
Description: Return the number of bytes in a string if expressed in LMBCS character set.
Strings in LotusScript are in Unicode, but are converted to LMBCS when stored
in items or passed to C API functions.
%END REM
Function LmbcsLen(x$) As Long
Dim session As New NotesSession, db As NotesDatabase, docTmp As NotesDocument
Dim mime As NotesMIMEEntity, streamIn As NotesStream, streamOut As NotesStream
Set db = session.CurrentDatabase
Set docTmp = db.CreateDocument
Set mime = docTmp.CreateMIMEEntity("Body")
Set streamIn = session.CreateStream
streamIn.WriteText x
streamIn.Position = 0
Call mime.SetContentFromText(streamIn, "text/plain;charset=LMBCS", ENC_NONE)
Set streamOut = session.CreateStream
mime.getContentAsBytes streamOut, False
LmbcsLen = streamOut.Bytes
End Function
Andre Guirard | 13 February 2012 06:06:17 PM ET | | Comments (4)
