Apostrophe in Zelle "escapen" - um zu entfernen

Programmierung unter AOO/LO (StarBasic, Python, Java, ...)

Moderator: Moderatoren

gigicarlo
*
Beiträge: 13
Registriert: Do, 17.07.2014 20:03

Apostrophe in Zelle "escapen" - um zu entfernen

Beitrag von gigicarlo »

Hallo zusammen

klingt einfach - aber ist wohl tricky - ich bekomme es nicht hin.


Hier ein Makro, das ich benutze um einen text so zu formatieren, dass er dann später als gültiger Dateiname taugt.

Was ich nicht hinbekomme, ist das Array so zu erweitern das ein " " " Apostrophe durch einen "_" ersetzt wird.

Habe alle Kombinationen von " und ' und "\" durchprobiert.

geht es einfach nicht ?

Oder weiß jemand einen Ausweg

Danke und Gruß

Luigi

Code: Alles auswählen

Sub fnKHM
oDoc = thisComponent
aFind = Array(" ", "ä" ,"\'", "\+" ,"ö" ,"ü", "-", "\.", "MS", "\(|\)", "ß", "_[0-9]_[0-9][0-9]min", "_+[0-9]+$", "_\&_",  "_\?", "_$", "Nt", "\*|\:", "_{2,}")

aReplace = Array("_", "ae", "", "_und_", "oe", "ue", "_", "_", "_MS_", "", "ss", "", "", "_", "_", "", "NT", "_", "_")   ' just for trying)
'aReplace = Array("១", "២", "៣", "៤", "៥", "៦", "៧", "៨", "៩", "០")

aRayCount = 0

oRange  = oDoc.getCurrentSelection() ' modified by Zizi64
FandR = oRange.createReplaceDescriptor() ' modified by Zizi64

FandR.SearchCaseSensitive = true
FandR.SearchRegularExpression = true


While aRayCount <= uBound(aFind)
FandR.setSearchString(aFind(aRayCount))
FandR.setReplaceString(aReplace(aRayCount))
aRayCount = aRayCount + 1

oRange.ReplaceAll(FandR)  ' modified by Zizi64

Wend
End Sub
Moderation: Zur übersichtlichen Darstellung von Programmcode im Text [​code][​/code] Tags gesetzt.
lorbass, Moderator
Karolus
********
Beiträge: 7532
Registriert: Mo, 02.01.2006 19:48

Re: Apostrophe in Zelle "escapen" - um zu entfernen

Beitrag von Karolus »

Hallo
in

Code: Alles auswählen

[code]
-tags[/code] würde dein Code so aussehen:

Code: Alles auswählen

Sub fnKHM
oDoc = thisComponent
aFind = Array(" ", "ä" ,"\'", "\+" ,"ö" ,"ü", "-", "\.", "MS", "\(|\)", "ß", "_[0-9]_[0-9][0-9]min", "_+[0-9]+$", "_\&_", "_\?", "_$", "Nt", "\*|\:", "_{2,}")

aReplace = Array("_", "ae", "", "_und_", "oe", "ue", "_", "_", "_MS_", "", "ss", "", "", "_", "_", "", "NT", "_", "_") ' just for trying)
'aReplace = Array("១", "២", "៣", "៤", "៥", "៦", "៧", "៨", "៩", "០")

aRayCount = 0

oRange = oDoc.getCurrentSelection() ' modified by Zizi64
FandR = oRange.createReplaceDescriptor() ' modified by Zizi64

FandR.SearchCaseSensitive = true
FandR.SearchRegularExpression = true


While aRayCount <= uBound(aFind)
FandR.setSearchString(aFind(aRayCount))
FandR.setReplaceString(aReplace(aRayCount))
aRayCount = aRayCount + 1

oRange.ReplaceAll(FandR) ' modified by Zizi64

Wend
End Sub
Zum Problem:

Code: Alles auswählen

Sub main
Print """"
End Sub
den "while....wend" -block könnte man besser als "for...next" schreiben:

Code: Alles auswählen

...
for i = 0 to uBound(aFind)
FandR.setSearchString(aFind( i ))
FandR.setReplaceString(aReplace( i ))
oRange.ReplaceAll(FandR) ' modified by Karolus ;-)'
next
...
 
Karolus
LO7.4.7.2 debian 12(bookworm) auf Raspberry5 8GB (ARM64)
LO25.2.3.2 flatpak debian 12(bookworm) auf Raspberry5 8GB (ARM64)
gigicarlo
*
Beiträge: 13
Registriert: Do, 17.07.2014 20:03

Re: Apostrophe in Zelle "escapen" - um zu entfernen

Beitrag von gigicarlo »

Vielen Dank !!!

Das hilft
Antworten