Need LotusScript code to escape backslashes and quotes

I need to find a replace function for LotusScript that will replace all double quotes (") in a string with backslash quote (") and all backslashes with a double backslash (\).

I have not had any luck with Evaluate and @ReplaceSubstring. Hopefully someone can help.

As an example, I want to this input string:

Amy replied, “The correct path is: c:\lotus\notes\data”.

… to be ouput as …

Amy replied, "The correct path is: c:\lotus\notes\data".

Thanks for any help you might offer.

Subject: Need LotusScript code to escape backslashes and quotes

I pinched this from this forum a few years ago …

Function fnReplaceSubString(_

Byval st As String, _

Byval f As String, _

Byval t As String) As String

'/**

'* Function replaceSubString

'* The following function will search the

'* passed string “st” for the string “f”. If

'* found all instances will be replaced with

'* the string “t”.

'*

'* @param st the string to be parsed

'* @param f the string that we are looking for

'* @param t the string that we would like “f”

'* to be changed to

'*

'* @return a new string with all instances “f”

'* replaced by “t”

'*

'*/

Dim returnValue As String

Dim temp As String

temp = st

Dim i As Integer

i = Instr(temp, f)



While (i > 0)

	returnValue = _

	returnValue + _

	Left(temp, i -1) + t

	temp = Mid(temp, i + Len(f))

	i = Instr(temp, f)

Wend



returnValue = returnValue + temp



fnReplaceSubString = returnValue

End Function

Subject: Need LotusScript code to escape backslashes and quotes

There is a “native” Replace function in LotusScript that should work provided that you do it in this sequence:

replace all backslash characters with backslash + backslash

replace all double quotes characters with backslash + double quotes.

Example:

Dim strVal As String

strVal$ = {Amy replied, “The correct path is: c:\lotus\notes\data”}

strVal$ = Replace(strVal$, "", “\”)

strVal$ = Replace(strVal$, {"}, {"})

Msgbox strVal$, , “DEBUG . . .”

It would be fairly trivial to do in Java using regular expressions too (if that’s an option).

dgg

Subject: RE: Need LotusScript code to escape backslashes and quotes

Thank you both very much!

I ended up trying the Replace function first, and it worked well. For some reason, I was too confused last week by the replace example provided in Designer help to just try simple strings.

Cheers,

Rob