【问题标题】:OpenOffice Writer macro remove apostrophe from StringOpenOffice Writer 宏从字符串中删除撇号
【发布时间】:2016-01-27 22:42:40
【问题描述】:

我正在 OpenOffice Writer 中编写宏。

我从 .xml 文件中读取文本并将其放入字符串中。 字符串将如下所示: "hello"(所以撇号也是字符串的一部分)

所以要清楚字符串看起来像这样(示例): String removeApostrophe = ""hello"".

我知道这很奇怪,但它是这样写在 .xml 文件中的。

我需要的是一个函数,我可以在其中放入该字符串并删除撇号,所以只有:你好会出来。

我试过但不可能的是替换功能:Replace(" "hello" ", """, "")

【问题讨论】:

    标签: replace macros apostrophe openoffice-writer


    【解决方案1】:

    函数调用:

    removeApostrophe = replace(removeApostrophe, chr(34), "")
    

    这是使用的函数:

    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
    

    首先我使用了:char(34),但这不起作用。所以我发现 chr(34) 是正确的使用方法。

    【讨论】: