Manage Learn to apply best practices and optimize your operations.

@Word in LotusScript

This function in LotusScript is equivalent to @Word function.

View member feedback to this tip.

This function in LotusScript is equivalent to @Word function:

Function Word(text As String, 
separateur As String, position As Integer) As 
 If text <>"" And separateur <>"" 
And position <> 0
  If position > 1 Then
   pos = position -1
   pos = position
  End If
  For i=1 To pos
   If position = 1 Then
    posActual = 0
    posActual =  Instr(posActual+1,text,separateur)
    If posActual = 0 Then
     Exit Function
    End If
   End If
   posNext =  Instr(posActual+1,text,separateur)
  If posNext <> 0 Then
   Word = Mid(text,posActual+1,posNext-(posActual+1)) 
   Word = Mid(text,posActual+1)
  End If
 End If
End Function


Several points:

This is not really equivalent to @Word.

  • @Word handles multivalued inputs for the first argument, not just strings.

  • @Word allows a negative position value to count backwards from the right end of the string.

  • The variables have not all been "dim"ed. That's a flaw -- it's inefficient, and it won't compile if the programmer has specified Option Declare in their script. (Note: If I were hiring Domino developers, I would ask them for samples of their LotusScript code, and I wouldn't hire someone who doesn't always use Option Declare. It just makes sense.)

  • Years ago I posted LotusScript implementations of all the common list and string @functions, available now along with a bunch of other useful stuff at This includes a more complete implementation of @Word than this one (as well as a simpler version that does what this one does and also handles negative positions).

  • In ND6, the built-in StrToken function does the same thing as this function.

Andre Guirard, expert


Andre's confirmation that LotusScript already contains an equivalent function to @Word highlights our community's tendency to keep reinventing wheels when IBM has already provided the wheels we're looking for. As you may recall, even when a function in Formula does not yet have a direct equivalent in LotusScript, one can always resort to use of the Evaluate() function, which evaluates Formula language within LotusScript and returns the result in an array:

Dim strSingleWord As String
Dim varEvaluateResult As Variant 
'Will store the evaluation result, 
bounds do not need to be specified
varEvaluateResult = Evaluate
 ( {@Word("Evaluate allows Formula 
to be called by
LotusScript"; " " ; 3)})
strSingleWord = varEvaluateResult(0) 
'In this case the array is single value 

—Tim T.


Why do developers keep trying to reinvent the wheel? If you really want the power of "@Word", why not take it?

        Function AtWord$( YourString$, 
YourSeparator$, YourNumber )
                YourNumber = Evaluate
( {@Word( "} & YourString$ & {"; "} & 
YourSeparator$ & {"; } & YourNumber & { )} )
                AtWord$ = YourNumber( 0 )
        End Function 

Note that I reuse the "YourNumber" variant to contain the array that the Evaluate function returns. Then, I make the return value scalar.

Most programmers do not use the Evaluate function because they have had problems creating the proper syntax. The "Gotcha!" is the escape character and quotes. It's frustrating, I know, but once you have your "Es" and "Qs" down, you can build quick and efficient LotusScript functions for many, if not all, formulas in the Formula language.

—Randall S.


ND6 users can use the StrToken LotusScript function as well.

—Joseph S.

Do you have comments on this tip? Let us know.

This tip was submitted to the tip library by member Evans Beeharry. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.

Dig Deeper on LotusScript



  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/ community. These cheat ...

  • HTML cheat sheet

    This is a really cool cheat sheet if you're looking to learn more about HTML. You'll find just about everything you every wanted ...

  • Carol Woodbury: Security

    Carol Woodbury