Notes Ninjas Notes Ninjas
Lotus Notes hints, tips, error messages
ReplaceSubString for Lotusscript

Hint Short Cut: Add this to your code & documentation to help you find this page.
http://www.notesninjas.com/#Replacesubstring-lotusscript or http://www.notesninjas.com/A555F9/nn.nsf/ByAlias/Replacesubstring-lotusscript


Replacesubstring is not a lotusscript function. Here's my version.





 

 

Function ReplaceSubString(Byval phrase$, Byval oldStr$, Byval newStr$) As String

' This function searches the string passed in phrase for all
' occurences of the string passed in oldStr. It then replaces
' the oldStr with the specified newStr. If an error occurs,
' a NULL value is returned ("").

Const FUNC_NAME= "ReplaceSubString2"
On Error Goto Errors
Dim begin%, found%, oldPhrase$

'---- Make sure that we have a phrase to change, and a string to look for:
If Strcompare(oldStr, "") = 0 Or Strcompare(phrase, "") = 0 Then Goto TheEnd
'---- Save the original string
oldPhrase= phrase

begin = 1
found = Instr(begin, phrase, oldStr, 1)
While (found > 0)
 begin = found + Len(newStr)
'---- Changing an instance of oldString
 phrase = Left$(phrase, (found - 1)) & newStr & Right$(phrase, Len(phrase) - (found + Len(oldStr) - 1))
'--- Looking for a new instance of oldString
 found = Instr(begin, phrase, oldStr, 1)
Wend
'---- Returning the new phrase changed
ReplaceSubString = phrase

TheEnd:
Exit Function

Errors:
'---- Returning the original value of phrase
ReplaceSubString = oldPhrase
Resume TheEnd
End Function

 

 Jump to:     Notes Tips
    Lotus Notes Index 
  Register for Tips
Previous Lotus Notes Tip 
    Next Lotus Notes Tip
Your company logo here?
Adam Foster
Free Cash Making Web Site
Free Revenue Earning Blog Site
 Free Revenue Earning Newsletter Site   
Free Search Pages Free Web stats
Free Contact Us page
Cheap .com domain names
 Need a website or 
   Lotus Notes
  problem solved?
Adam Foster
Lotus Notes and Domino 6 Programming Bible by Brian Benz, Rocky Oliver
Covers all the programming techniques, concepts, and languages used with Notes and Domino, as well as the many new features of Domino 6 Thoroughly examines the Notes and Domino role with Java, XML, Web services, and other IBM products and technologies Provides extensive code and examples, many geared to the needs of administrators High-profile authors, known to their audience through conferences and articles Companion Web site shows example applications from the book running on a live Domino server and provides code download.
See at: Amazon.co.uk | Amazon.com |