Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 15th, 2012  |  syntax: None  |  size: 0.99 KB  |  hits: 3  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.     private void generateRE(String word)
  2.     {
  3.         // ALL SUBSTITUTIONS OF 1 CHARACTER
  4.         for (int i=0; i<word.length(); i++)
  5.         {
  6.             Character c = word.charAt(i);
  7.             String s = word.replace(c.toString(), "[a-z]");
  8.            
  9.             System.out.println("Sub: \\n" + s + "\\n");
  10.         }
  11.  
  12.         // ALL INSERTIONS OF 1 CHARACTER
  13.         System.out.println("Ins: \\n[a-z]"+word+"\\n");
  14.         for (int i=0; i<word.length()-1; i++)
  15.         {
  16.             System.out.println("Ins: \\n" + word.substring(0, i+1) + "[a-z]" + word.substring(i+1, word.length()) + "\\n");
  17.         }
  18.         System.out.println("Ins: \\n"+word+"[a-z]\\n");
  19.  
  20.         // ALL DELETIONS OF 1 CHARACTER
  21.         for (int i=0; i<word.length(); i++)
  22.         {
  23.             System.out.print("Del: \\n");
  24.             for (int j=0; j<word.length(); j++)
  25.             {
  26.                 if (i!=j)
  27.                     System.out.print(word.charAt(j));
  28.             }
  29.             System.out.println("\\n");
  30.         }
  31.     }