You are viewing a single comment's thread.

view the rest of the comments →

0
1

[–] thephantompoop 0 points 1 point (+1|-0) ago  (edited ago)

I had a whole explanation written out, but the page refreshed and i lost it and i need to write an essay soon -,-

So here's the run-down

after you assign the sentence to a string, you should use

sentence = sentence.replaceAll("[^\w\s]","");

This removes all non-whitespace and non-letter/number characters. You string will be "This is my homework".

After this,

word = sentence.split(" ").length;

This turns sentence into a static array of length 4:

[This, is, my, homework]

A handy site to explain what I just did:

Regex

A handy site for testing regex with a quick reference chart at the bottom:

Rubular

0
1

[–] tragicwhale [S] 0 points 1 point (+1|-0) ago 

Hey Phantom, That is spectacular information as I had never seen those methods before. Thanks for the website too as it's just another tool in my toolbox. Really appreciate all the help.