FindAndReplace in LotusScript

There’s @ReplaceSubstring in formula, there’s the FindAndReplace method for a NotesRichtextRange in LotusScript, but it doesn’t exist for a ordinary string.

This is the shortest (one line of code) function I can think of to build my own FindAndReplace. It can be a very old tip, or a very obvious one, I don’t know.

It’s really easy: I just split a string with the text-to-find as “splitter”, and join it back with the replacement text.

Function FindAndReplace(SourceText As String,FindText As String,ReplaceText As String) As String
	FindAndReplace=Join(Split(SourceText,FindText),ReplaceText)
End Function

Gimme some feedback! Do you know this for years? Do you have another way of achieving this? Are there downsides?

4 Comments

  1. Martin,
    Why don’t you just use the ‘built-in’ Replace function ?

    Reply
  2. Hi Theo,
    According to Designer Help, this function is meant to replace elements in arrays. Or maybe you know how to use it in a different way?

    Reply
  3. Hi Martin,

    The built-in Replace function works just fine on plain strings.

    Example:
    strMyString = Replace(strMyString, “”, “Ken”)

    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

7 + 1 =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>