Suche nach Regex zum ersetzen von Umlauten

  • Sonstige

Es gibt 8 Antworten in diesem Thema. Der letzte Beitrag () ist von Schamash.

    Suche nach Regex zum ersetzen von Umlauten

    Hallo zusammen,

    ich versuche mich zur Zeit ein wenig an Regex.
    Zur Zeit Sorge ich dafür das meine Namenschreibweise fals sie Umlaut enthält so umgebaut wird.
    Jetzt hab ich gesehen das Regex auch replace kann. Ich bekomme es aber nicht hin den Aufruf korrekt umzusetzen.

    VB.NET-Quellcode

    1. If Regex.IsMatch(Name, "ä|ö|ü|Ä|Ö|Ü") Then
    2. nName = Name.Replace("ä", "ae").Replace("ö", "oe").Replace("ü", "ue").Replace("Ä", "Ae").Replace("Ü", "Ue").Replace("Ö", "Öe")
    3. End If


    so schaut mein Regex Versucht aus:

    VB.NET-Quellcode

    1. If Regex.IsMatch(Name, "Ä|ä|Ö|ö|Ü|ü") Then
    2. Dim pattern As String = "Ä|ä|Ö|ö|Ü|ü"
    3. Dim replacement As String = "Ae|ae|Oe|oe|Ue|ue"
    4. Dim rgx As New Regex(pattern)
    5. Dim nName As String = rgx.Replace(Name, replacement)
    6. End If
    There is no CLOUD - just other people's computers

    Q: Why do JAVA developers wear glasses?
    A: Because they can't C#

    Daily prayer:
    "Dear Lord, grand me the strength not to kill any stupid people today and please grant me the ability to punch them in the face over standard TCP/IP."
    Meine Idee dazu:

    VB.NET-Quellcode

    1. Private Function ReplaceUmlauts(ByVal text As String) As String
    2. Dim reps = New Dictionary(Of String, String)() From {{"Ä", "Ae"}, {"ä", "ae"}, {"Ö", "Oe"}, {"ö", "oe"}, {"Ü", "Ue"}, {"ü", "ue"}}
    3. Return New System.Text.RegularExpressions.Regex(String.Join("|", reps.Keys)).Replace(text, Function(rep) reps(rep.Value))
    4. End Function
    And i think to myself... what a wonderfuL World!
    Besten Dank.

    Ich muss mich damit dringend intensiver beschäftigen.
    Zur Zeit verstehe ich was da steht könnte das aber nicht neu erstellen ohne abschreiben :)
    There is no CLOUD - just other people's computers

    Q: Why do JAVA developers wear glasses?
    A: Because they can't C#

    Daily prayer:
    "Dear Lord, grand me the strength not to kill any stupid people today and please grant me the ability to punch them in the face over standard TCP/IP."

    Link schrieb:

    vornherein den richtigen Zeichensatz wählt?


    Das sollte man meinen.
    Allerdings bringe ich in meinem Tool werte von 4 Programmen zusammen. Die Namen wurden aber auch innerhalb eines Programms nicht immer gleich gepflegt. Mal ist ein Name mit oe und mal mit ö.
    Jetzt habe ich keine Lust ein Ausnahmelist oder sonstiges zu führen und alls Sonderfälle darin aufzuführen. Die Lösung ist für mich komfortabler.
    Ich muss mich noch mit genug anderen "Pflegemissständen" rumärgern - Doppelnamen ... ganz schlimm
    Hans Peter Müller
    Hans Peter Mueller
    Müller, Hans Peter
    Mueller, Hans-Peter
    Peter Müller, Hans <-- Ja selbst diesen Fall gibt es.
    Und natürlich ist es "Zu viel aufwand" die Schreibweise im original Programm zu korrigieren
    There is no CLOUD - just other people's computers

    Q: Why do JAVA developers wear glasses?
    A: Because they can't C#

    Daily prayer:
    "Dear Lord, grand me the strength not to kill any stupid people today and please grant me the ability to punch them in the face over standard TCP/IP."
    @us4711 das stimmt, in meinem Fall ist es aber alles der Selbe. Der Name war auch nur ein Beispiel. Meistens ist es das ein "Herr Müller" in 1-2 der 4 Programme abweichend geschrieben ist.

    Das "schöne" daran wie ich den Code nun verwende ist das, wenn es zu Müller keinen Treffer gibt suche ich auch mal nach Mueller.
    Der Nachname ist allerdings nicht der Primärschlüssel so das die Zuordnung selbst bei gleichen Namen möglich wird.
    There is no CLOUD - just other people's computers

    Q: Why do JAVA developers wear glasses?
    A: Because they can't C#

    Daily prayer:
    "Dear Lord, grand me the strength not to kill any stupid people today and please grant me the ability to punch them in the face over standard TCP/IP."
    Und Daten seit dem letzten Jahrhunder nicht angepasst wurden.
    Nach einem Update war bei Prog. 1 möglich Umlaute im Namen zu speichern, also wurden ab dann alle Namen auch mit Umlauten gespeichert. Die alten Namen wurden natürlich nicht angepackt. :)

    Daher hat heist Frau Müller vor der Elternzeit Mueller und nach der Elternzeit Müller ... Jippy!!!
    There is no CLOUD - just other people's computers

    Q: Why do JAVA developers wear glasses?
    A: Because they can't C#

    Daily prayer:
    "Dear Lord, grand me the strength not to kill any stupid people today and please grant me the ability to punch them in the face over standard TCP/IP."