[Solved] Escape single quote in a string variable

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
V1ce
Posts: 12
Joined: Thu Aug 02, 2018 4:39 pm

[Solved] Escape single quote in a string variable

Post by V1ce »

Hi,

In my macro i have to handle some variable string with single quote, no problem for manipulate them but at a moment this break my instructions, i try to escape them with this function but i get an "incorrect property value" error. Im not sure this is the function that i need. I have try to use instr() and mid() but no result.

Code: Select all

name = Replace(name, chr(39), "\'")

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
Thanks for your help
Last edited by robleyd on Wed Aug 08, 2018 11:55 am, edited 2 times in total.
OpenOffice 4.1.2
V1ce
Posts: 12
Joined: Thu Aug 02, 2018 4:39 pm

Re: macro - Escape single quote in a string variable

Post by V1ce »

This is solved i have remove the quote retype it and now the program take it without error... Data come from openoffice and im with Libreoffice maybe some difference...
OpenOffice 4.1.2
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: [SOLVED]macro - Escape single quote in a string variable

Post by RoryOF »

It may be that the quote had been turned into a curly quote, particularly if the file had been prepared in Writer.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
Post Reply