-
-
Save javatlacati/af7fb60e3bb2a63559ae to your computer and use it in GitHub Desktop.
Estadísticas de cadenas
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 (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(); | |
} | |
} |
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: 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