I am writing a macro in OpenOffice Writer.
I read text from a .xml file and put that into a String. The String will look like this: "hello" (so the apostrophe are also part of the String)
So to be clear the String looks like this(Example): String removeApostrophe = ""hello"".
I know it is weird but it's written in the .xml file that way.
What I need is a function where I can put that String in and removes the apostrophe so only: hello will come out.
Something I tried but is not possible is the Replace function: Replace(" "hello" ", """, "")
Function call:
removeApostrophe = replace(removeApostrophe, chr(34), "")
This is the function used:
Function Replace(removeApostrophe As String, Search As String, NewPart As String)
Dim Result As String
Dim StartPosition As Long
Dim CurrentPosition As Long
Result = ""
StartPosition = 1
CurrentPosition = 1
If Search = "" Then
Result = removeApostrophe
Else
Do While CurrentPosition <> 0
CurrentPosition = InStr(StartPosition, removeApostrophe, Search)
If CurrentPosition <> 0 Then
Result = Result + Mid(removeApostrophe, StartPosition, _
CurrentPosition - StartPosition)
Result = Result + NewPart
StartPosition = CurrentPosition + Len(Search)
Else
Result = Result + Mid(removeApostrophe, StartPosition, Len(removeApostrophe))
End If ' Position <> 0
Loop
End If
Replace = Result
End Function
First I used: char(34), but that doesn't work. So I found out chr(34) was the right thing to use.