Entries tagged replace

Using a Perl script because refactoring of a project with Android tools didn’t work

Posted on 20. Dezember 2014 Comments

I wanted to rename my project but I guess since it has a lot of dependencies that caused an error somewhere and I got the error message:

Refactoring
A fatal error occurred while performing the refactoring.
An unexpected exception occurred while creating a change object. See the error log for more details.

So I just the normal refactoring feature of Eclipse which not surprisingly also caused an error. After editing the AndroidManifest package entry, the import of the resources in the sources files didn’t work. It still said

import com.example.oldpackage.R

Only a couple of resource files needed manual editing but the Java files were a problem. What did the trick for me was this one-liner

perl -pi -w -e 's/import com.example.oldpackage.R/import com.example.newpackage.R/g;' `grep -r -l "import com.example.oldpackage.R"`

I realise this is rather quick&dirty (do a backup 😉 ) but it did work for this project. A short explanation:

perl

  • -pi puts the code in a loop (like -n, but sed-style)
  • -w gives you warnings
  • -e is one line of programm and since -pi
  • /g global, for all lines in the file

grep

  • -r recursive
  • -l give out files that matches the following search string

Libre Office Calc Makro zum Ersetzen von Sonderzeichen in BASIC

Posted on 22. Mai 2014 Comments

Dieses Makro ersetzt in einem LibreOffice Calc Sheet alle norwegischen Sonderzeichen (å, ø, æ) durch ASCII kompatible Zeichen.

Sub NO_WITHOUT_SPECIAL_CHARS()

    dim oSheet as object, mySuche as Object
    'erste Tabelle
    oSheet = thisComponent.Sheets.getByIndex(0)
    mySuche=oSheet.createReplaceDescriptor()
    
    With mySuche
    .SearchRegularExpression = False
    .setSearchString("å")
    .setReplaceString("a")
    end With
    oSheet.replaceAll(mySuche)
    
    With mySuche
    .SearchRegularExpression = False
    .setSearchString("ø")
    .setReplaceString("o")
    end With
    oSheet.replaceAll(mySuche)

    With mySuche
    .SearchRegularExpression = False
    .setSearchString("æ")
    .setReplaceString("ae")
    end With
    oSheet.replaceAll(mySuche)
End Sub

Eine Anleitung, wie man das Makro in die Symbolleiste bekommt, findet sich im OpenOffice Wiki.