Skip to content

Instantly share code, notes, and snippets.

@javatlacati
Forked from jtulach/HelloViaKO.java
Last active April 25, 2019 03:36
Show Gist options
  • Save javatlacati/af7fb60e3bb2a63559ae to your computer and use it in GitHub Desktop.
Save javatlacati/af7fb60e3bb2a63559ae to your computer and use it in GitHub Desktop.
Estadísticas de cadenas
package dew.demo.string;
import net.java.html.json.Model;
import net.java.html.json.ComputedProperty;
import net.java.html.json.Property;
@Model (targetId="",className = "StringStatistics", properties = {
@Property (name = "miTexto", type=String.class)
})
class PrimeDemo {
@ComputedProperty static int letras (String miTexto) {
return miTexto.length();
}
@ComputedProperty static int vocales (String miTexto) {
return miTexto.length()-miTexto.replaceAll("[aeiouAEIOU]","").length();
}
@ComputedProperty static int consonantes (String miTexto) {
return miTexto.length()-miTexto.replaceAll("[b-df-hj-np-tv-zB-DF-HJ-NP-TV-Z]","").length();
}
@ComputedProperty static int espacios (String miTexto) {
return miTexto.length()-miTexto.replaceAll("[ ]","").length();
}
public static void main(String... args) {
new StringStatistics("").applyBindings();
}
}
<textarea
data-bind="value: miTexto, valueUpdate: 'afterkeydown'"
placeholder="Escriba un texto para analizar...">
</textarea>
<p>
La cadena <pre data-bind="text: miTexto"></pre> tiene
<ul>
<li data-bind="text: letras()+' letras.'"></li>
<li data-bind="text: vocales()+' vocales.'"></li>
<li data-bind="text: consonantes()+' consonantes.'"></li>
<li data-bind="text: espacios()+' espacios.'"></li>
</ul>
<br>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment