Skip to main content
    Country/region select      Terms of use
     Home      Products      Services & solutions      Support & downloads      My account     

developerWorks  >  Lotus  >  Forums & community  >  Best Practice Makes Perfect

Best Practice Makes Perfect

A collaboration with Domino developers about how to do it and how to get it right in Domino

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.


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 =
Call mime.SetContentFromText(streamIn, "text/plain;charset=LMBCS", ENC_NONE)
Set streamOut = session.CreateStream
       mime.getContentAsBytes streamOut,
       LmbcsLen = streamOut.Bytes


Andre Guirard | 13 February 2012 06:06:17 PM ET | | Comments (6)

Search this blog 


    About IBM Privacy Contact