BizzyBee’s BizzyThoughts

Think Outside The Hive - About Notes and Web
 
 

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?


1 Star2 Stars3 Stars4 Stars5 Stars (4 votes, average: 3.25 out of 5)
Loading ... Loading ...

4 Responses to “FindAndReplace in LotusScript”

  1. Gravatar Theo Heselmans says:

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

  2. Gravatar Martin Vereecken says:

    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?

  3. Gravatar Ken Haggman says:

    Hi Martin,

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

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

  4. Gravatar Martin Vereecken says:

    Okay… Thanks for learning me this!

Leave a Reply