Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Replace substring in LotusScript

2,618 views
Skip to first unread message

suesp...@sue.com

unread,
Oct 6, 2000, 3:00:00 AM10/6/00
to
Hi,

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

hp

unread,
Oct 6, 2000, 10:37:26 PM10/6/00
to
you can use it with Evaluation and @replacesubstring
such as Evaluation({@replacesubstring(originalString; substringA;
substringB)})

Christian Patterer

unread,
Oct 7, 2000, 3:00:00 AM10/7/00
to
I created following script. May be there are more elegant ways but it
works fine for me...

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.

dpsa

unread,
Oct 7, 2000, 3:00:00 AM10/7/00
to
Hi,

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


0 new messages