-1

Twitterのデータを集めて加工しているのですが、文字が汚い、

例 :

String dirtyText="this*is#a*&very_dirty&String";

例 :

String dirtyText="All f dis happnd bcause u gave ur time, talent n passion.";

できるだけシンプルにしたいです。

4

3 に答える 3

0

public class CleaningDirtText { private static final String dirtyText = "これ#a &very_dirty&String";

public static void main(String[] args) {
    /*
     * remove leading and trailing spaces, and split our words into a String array.
     * The split method allows you to break apart text on a given delimiter. In this
     * case, we chose to use the regular expression \\W, which represents anything
     * that is not a word character:
     */

    System.out.println(dirtyText);
    String[] words = dirtyText.toLowerCase().trim().split("[\\W\\d]+");
    for (int i = 0; i < words.length; i++) {
        System.out.print(words[i]);
    }
    System.out.println("\nsee the cleand text:-");
    for (String clean : words) {
        System.out.print(clean + " ");
    }
}

}

于 2021-08-18T21:06:58.963 に答える