0

有人知道如何像str_ireplacePHP 一样在 Libreoffice 中创建基本功能吗?
我想在我的细胞功能中使用。

str_ireplace(search - range of cells, replace - range of cells, text)

或者至少str_replace

4

2 回答 2

1

我做了非常简单的功能

Function Str_ireplace(Search As Variant, Replace As Variant, Source As String)

  Dim Result As String
  Dim StartPos As Long
  Dim CurrentPos As Long
  Dim CurrentSearch As String
  Dim CurrentReplace As String

  Result = ""

  For Row = Lbound( Search, 1 ) To Ubound( Search, 1 )
    For Col = LBound(Search, 2) To UBound(Search, 2)
        StartPos = 1
        CurrentPos = 1
        CurrentSearch = Search(Row, Col)
        CurrentReplace = Replace(Row, Col)
        Result = ""


        Do While CurrentPos <> 0
            CurrentPos = InStr(StartPos, Source, CurrentSearch)
            If CurrentPos <> 0 Then
                Result = Result + Mid(Source, StartPos, _
                CurrentPos - StartPos)
                Result = Result + CurrentReplace
                StartPos = CurrentPos + Len(CurrentSearch)
            Else
                Result = Result + Mid(Source, StartPos, Len(Source))
            End If                ' Position <> 0
        Loop
        Source = Result 
    Next 
  Next


  Str_ireplace = Result    
End Function

我以此为例: http://wiki.openoffice.org/wiki/Documentation/BASIC_Guide/Strings_(Runtime_Library)

于 2013-04-13T17:32:50.657 回答
0

尝试这个

句法

替换(“文本”;位置;长度;“新文本”)

文本是指将替换一部分的文本。

位置是指替换将开始的文本中的位置。

长度是要替换的文本中的字符数。

NewText 是指替换 Text 的文本。

例子

=REPLACE("1234567";1;1;"444") returns "444234567". One character at position 1 is replaced by the complete NewText.

https://help.libreoffice.org/Calc/Text_Functions#Example_13

或者

SUBSTITUTE(“文本”;“搜索文本”;“新文本”;出现次数)

例子

=SUBSTITUTE("123123123";"3";"abc") 返回 12abc12abc12abc。

=SUBSTITUTE("123123123";"3";"abc";2) 返回 12312abc123。

https://help.libreoffice.org/Calc/Text_Functions#SUBSTITUTE

于 2013-04-13T15:27:41.083 回答