0

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" ", """, "")

476rick
  • 2,764
  • 4
  • 29
  • 49

1 Answers1

0

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.

tohuwawohu
  • 13,268
  • 4
  • 42
  • 61
476rick
  • 2,764
  • 4
  • 29
  • 49