How I can split the sentences with respect to the delimiters in the string and count the frequency of words ?
String delimiters = "\t,;.?!-:@[](){}_*/";
My text file is:
Billy_Reeves
Smorz
Nationalist_Left_-_Youth
Ancient_Greek_units_of_measurement
Jiuting_(Shanghai_Metro)
Blodgett,_MO
Baekjeong
Matt_Brinkman
National_Vietnam_Veterans_Art_Museum
Using String. split() Method. The split() method of the String class is used to split a string into an array of String objects based on the specified delimiter that matches the regular expression.
In order to break String into tokens, you need to create a StringTokenizer object and provide a delimiter for splitting strings into tokens. You can pass multiple delimiters e.g. you can break String into tokens by, and: at the same time. If you don't provide any delimiter then by default it will use white-space.
split("\\s+") will split the string into string of array with separator as space or multiple spaces. \s+ is a regular expression for one or more spaces.
String s[]= txtArea. getText(). split("\\n");
Try with
split("\\t|,|;|\\.|\\?|!|-|:|@|\\[|\\]|\\(|\\)|\\{|\\}|_|\\*|/");
Also
Use String.split() with multiple delimiters
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With