在Visual Basic VBAstring中的每个引号之前插回斜杠

正如标题所说,我想在Visual Basic VBAstring的每个引号之前插回斜杠。 谢谢。

以下是我现在要做的(甚至不编译):

Dim n As Integer n = UBound(value) - LBound(value) + 1 Dim parsedValue As String parsedValue = value For i = 1 To n If parsedValue.Chars(i) = "'" Then n = n + 1 parsedValue = Left(parsedValue, i) + "\'" + Right(parsedValue, n - i) i = i + 1 End If Next 

下面是一个非常简单的例子,在string中的每个引号之前插入backslash ,而不用循环整个string。

 Sub Sample() Dim sString As String sString = "This is a sample string has 'quotes' in it" Debug.Print sString 'This is a sample string has 'quotes' in it sString = Replace(sString, "'", "\'") Debug.Print sString 'This is a sample string has \'quotes\' in it End Sub