Disemvowel in swift -


we can remove of vowels string in javascript this:

function disemvowel(str) {   str = str.replace(/([aeiouaeiou])/g, '')   return str; } 

i implement same function in swift, curious how can write shorter javascript?

func disemvowelthestring(string: string) -> string {   var replacedstring = string   let vowels = ["a", "e", "i", "o", "u", "a", "e", "i", "o", "u"]    vowel in vowels {     if string.containsstring(vowel) {       replacedstring = replacedstring.stringbyreplacingoccurrencesofstring(vowel, withstring: "")     }   }    return replacedstring } 

one option filter vowels input string's characters:

func removevowels(input: string) -> string {     let vowels: [character] = ["a", "e", "i", "o", "u", "a", "e", "i", "o", "u"]     let result = string(input.characters.filter { !vowels.contains($0) })     return result } 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -