-
-
Save javatlacati/fd4a282ff87f23473914c68baae95d03 to your computer and use it in GitHub Desktop.
Simple text statistics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<textarea | |
data-bind="value: myText, valueUpdate: 'afterkeydown'" | |
placeholder="Type a text to analyze..."> | |
</textarea> | |
<p> | |
The string <pre data-bind="text: myText"></pre> has | |
<ul> | |
<li data-bind="text: letters()+' letters.'"></li> | |
<li data-bind="text: vowels()+' vowels.'"></li> | |
<li data-bind="text: consonants()+' consonants.'"></li> | |
<li data-bind="text: spaces()+' spaces.'"></li> | |
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package dew.demo.string; | |
import net.java.html.json.Model; | |
import net.java.html.json.ComputedProperty; | |
import net.java.html.json.Property; | |
@Model(className="StringStatistics", properties={ | |
@Property(name="myText", type=String.class) | |
}) | |
class StringDemo { | |
@ComputedProperty static int letters(String myText) { | |
return myText.length(); | |
} | |
@ComputedProperty static int vowels(String myText) { | |
return myText.length()-myText.replaceAll("[aeiouAEIOU]","").length(); | |
} | |
@ComputedProperty static int consonants(String myText) { | |
return myText.length()-myText.replaceAll("[b-df-hj-np-tv-zB-DF-HJ-NP-TV-Z]","").length(); | |
} | |
@ComputedProperty static int spaces(String myText) { | |
return myText.length()-myText.replaceAll("[ ]","").length(); | |
} | |
static { | |
new StringStatistics("").applyBindings(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment