Can anyone provide sample code in Lotus Script to replace a substringA
to SubstringB in a String.
E.g. ABCdefg;
When substringA = def, replace it with substringB =XYZ,
so the result is ABCXYZg.
Thanks
Climber
Regards,
Chris
-------------------
Public Function ReplaceSubstring(sourceString As String, fromString As
String, toString As String) As String
'Declarations
Dim newString As String
Dim position As Integer
'Create the new string
position = 1
newString = sourceString
'Search for fromString
position = Instr(sourceString, fromString)
If position <> 0 Then
newString = Left(newString, position-1) & Mid(newString,
position+Len(fromString))
newString = ReplaceSubstring(newString, fromString, toString)
End If
'Return the new string
ReplaceSubstring = newString
End Function
Sent via Deja.com http://www.deja.com/
Before you buy.
Try this :
Function ReplaceSubstring( sourceStr As String, findStr As String,
replaceStr As String) As String
Dim replaceLen As Integer
Dim nextFound As Integer
Dim startPos As Integer
replaceLen = Len(replaceStr)
startPos = 1
nextFound = Instr( sourceStr, findStr)
If nextFound = 0 Then
ReplaceSubstring = sourceStr
Exit Function
End If
While Not nextFound = 0
ReplaceSubstring = ReplaceSubstring + Mid$( sourceStr, startPos,
nextFound-startPos) + replaceStr
startPos = nextFound + replaceLen
nextFound = Instr( startPos, sourceStr, findStr)
Wend
If startPos < Len( sourceStr) Then
ReplaceSubstring = ReplaceSubstring + Right$( sourceStr, Len( sourceStr) -
startPos + 1)
End If
End Function
Exemple :
Print "[/" + ReplaceSubstring(db.FilePath, "\", "/") + "/LookupView/" +
doc.UniversalID + "?EditDocument]"
--
il ne va pas bien loin celui qui sait d'avance ou il va.
Napoleon