Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

194
Views
¿Cómo contar la cantidad de vocales, consonantes y caracteres en una cadena usando react native?

quiero contar el número de consonantes/vocales/caracteres dependiendo de la palabra dada por el usuario, luego el resultado se muestra en la pantalla. He tratado de resolver sin embargo todavía no apareció

 export default class App extends Component{ constructor(){ super(); this.state ={ value: '', consonant: 0, vowels: 0, characters:0, } } WordAnalyzer = () => { this.setState({value: this.state.value}), () => { const listVowel=['a','i','u','e','o','A','I','U','E','O']; let arr_word= this.state.value.split(''); for (let j=0; j<arr_word.length; j++){ for (let i=0; i< listVowel.length; i++){ if (arr_word[j] == listVowel[i]){ this.setState({vowels: this.state.vowels + 1}); } else{ this.setState({consonant: this.state.consonant +1}); } } this.setState({characters: this.state.characters +1}); } }; } render(){ return( <View style={styles.container}> <Text style={styles.header}>Word Analyzer</Text> <TextInput style= {styles.input} onChangeText={(value) =>this.setState({value})} placeholder='Input a word here' /> <Button color = '#841584' onPress={this.WordAnalyzer} title='Analyze'/> <Text>Word : {this.state.value}</Text> <Text>No of Consonants: {this.state.consonant}</Text> <Text>No of Vowels : {this.state.vowels}</Text> <Text>No of Characters: {this.state.characters}</Text> </View> ); } }

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Sería mucho menos trabajo (tanto para usted como para su computadora) si simplemente usara la match en la cadena para averiguar cuántas vocales y consonantes hay en ella.

Y, por supuesto, simplemente puede usar this.state.value.length para obtener la cantidad de caracteres.

Por lo tanto, WordAnalyzer se puede refactorizar en algo mucho más simple:

 WordAnalyzer = () => { const vowelsCount = this.state.value.match(/[AaEeIiOoUu]/g).length; this.setState({ characters: this.state.value.length, vowels: vowelsCount, consonant: this.state.value.match(/[a-zA-z]/g).length - vowelsCount }); };
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!