java - Dividing a string into all possible 4-letter consequent phrases -
what i'm trying this:
- read file;
- remove punctuation , convert letters lowercase;
- convert words 4 letter phrases (if word shorter 4 characters, take whole);
example:
input: hello, identification mister dude.
output: hell, ello, my, iden, dent, enti, ntif, tifi, ific, fica, icat, cati, atio, tion, is, mist, iste, ster, dude.
it nice if each 4-word phrase separate value in array.
now things i've managed complete:
public string[] openfile() throws ioexception { filereader fr = new filereader(path); bufferedreader textreader = new bufferedreader(fr); int numberoflines = readlines(); string[] textdata = new string[numberoflines]; int i; (i = 0; < numberoflines; i++) { textdata[i] = textreader.readline(); textdata[i] = textdata[i].replaceall("[^a-za-ząčęėįšųūž]+", " ").tolowercase(); } textreader.close(); return textdata; } the textdata[i] each line of text need divide. i've tried several methods, such .tochararray , 2d arrays can't seem manage letter arrangement part. how can complete task no.3?
tested on ideone.com:
public static void main (string[] args) { string text = "hello, identification mister dude."; string[] words = text.replaceall("[^(\\w )]+", "").tolowercase().split(" "); (string word : words) { if (word.length() <= 4) { system.out.println(word); } else { (int = 0; <= word.length() - 4; i++) { system.out.println(word.substring(i, + 4)); } } } }
Comments
Post a Comment