Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

RegExpr. Values maskieren

Empfohlene Antworten

Veröffentlicht

Moin,

heute wieder mal ein kleines Problem, wer kann mir helfen.

1. Ich weiß, dass ich es auch selbst machen könnte, aber vielleicht

muß ich das ja gar nicht, deshalb meine Frage.

Ich möchte, dass ein Benutzer wo auch immer definieren kann, was er von

einem String entfernen möchte, z.B. der Ausgangsstring "H.H....[]..." usw. - gibt jetzt der Benutzer "." all = "true" und "[]" all = "true" an, so werden alle Zeichen entfernt mit dem Endergebnis "HH". ... leider sind auch hier Werte dabei ".[]", die Steuerzeichen in Expressionvalues sind, d.h. ich muss jedes einzelne maskieren, wenn ich java.lang.String.replace(All) verwenden möchte - so nun meine Frage, gibt es schon in Java eine vorgefertigte Methode, die genau alle diese Steuerzeichen maskiert?

Gruß

P.S. Ohne maskieren klappt es nicht (immer), so wird z.B. aus H.....o einfach ein kompletter Leerstring oder auch können Fehlermeldungen kommen "[]"

Moin,

für alle, die mal das gleiche Problem haben und keine Standardlösung finden können:

public static String replace(String replaceWith, String replaceFrom,

    String content, boolean replaceAll, boolean ignoreCase) {

    String replace = content;

    if(!ValueUtil.isEmpty(replaceWith)

      && ValueUtil.isNotEmptyOrDefault(content)) {

      int startIndex = ignoreCase ? StringUtil.getIndexOfIgnoreCase(replace,

        replaceFrom, 0) : replace.indexOf(replaceFrom);

      int endIndex = ValueUtil.INT_TYPE_EMPTY;

      String prefix = ValueUtil.STRING_EMPTY;

      String postfix = ValueUtil.STRING_EMPTY;

      while(startIndex != -1) {

        prefix = replace.substring(0, startIndex);

        postfix = replace.substring(startIndex + replaceFrom.length());

        replace = prefix + replaceWith + postfix;

        if(!replaceAll) {

          break;

        }

        endIndex = (prefix + replaceWith).length();

        startIndex = ignoreCase ? StringUtil.getIndexOfIgnoreCase(replace,

          replaceFrom, endIndex) : replace.indexOf(replaceFrom, endIndex);

      }

    }

    return replace;

  }


und hier noch meine ältere Hilfsmethode, die innerhalb von replace benutzt wird:

public static int getIndexOfIgnoreCase(String fromString,

    String searchString, int indexStart) {

    int index = ValueUtil.INT_TYPE_EMPTY;

    if(ValueUtil.isNotEmptyOrDefault(fromString)

      && ValueUtil.isNotEmptyOrDefault(searchString)) {

      index = fromString.toUpperCase().indexOf(searchString.toUpperCase(),

        indexStart);

    }

    return index;

  }


Die ValueUtil-Variablen sind einfach Defaultwerte (MIN, null, Leerstring usw.)

Grüße und frohes schaffen :D

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.