Untitled
unknown
plain_text
a year ago
2.4 kB
1
Indexable
Never
package com.mycompany.zanaA; public class ZanaA { public static void main(String[] args) { System.out.println(istTeilwortAnIndex("adasbcdef", "kf", 1)); System.out.println(findeTeilWort("abcdeabf", "ab")); System.out.println(loescheTeilwort("abcdeabf", "ab")); System.out.println(loescheAlleTeilwort("abcdeabf", new String[] { "ab", "cd" })); } static boolean istTeilwortAnIndex(String w, String v, int i) { //10 - 4 for (int j = i; j < w.length() - v.length(); j++) { String vTmp = ""; for (int k = j; k < v.length() + j; k++) { vTmp += w.charAt(k); } if (vTmp.equals(v)) { return true; } } return false; } static int findeTeilWort(String w, String v) { if (istTeilwortAnIndex(w, v, 0)) { for (int i = 0; i < w.length(); i++) { String vTmp = ""; for (int k = i; k < v.length() + i; k++) { vTmp += w.charAt(k); } if (vTmp.equals(v)) { return i; } } } return -1; } // System.out.println(loescheTeilwort("abcdeabf", "ab")); static String loescheTeilwort(String w, String v) { if (!istTeilwortAnIndex(w, v, 0)) { return null; } String tmp = ""; int index = findeTeilWort(w, v); for (int i = 0; i < w.length(); i++) { if (i < index || i >= index + v.length()) { tmp += w.charAt(i); } } return tmp; } // System.out.println(loescheAlleTeilwort("abcdeabf", new String[]{"ab","cd"})); static String loescheAlleTeilwort(String w, String[] vArray) { String tmp = w; for (int j = 0; j < w.length(); j++) { for (int k = 0; k < vArray.length; k++) { if (istTeilwortAnIndex(tmp, vArray[k], 0)) { tmp = loescheTeilwort(tmp, vArray[k]); } } } return tmp; } }