ios - Swift: how to censor/filter text entered for swear words, etc? -


i want see whether there established way this, or how 1 go this.

i have text field acts form in ios app user can post something. can't have users posting swear words/inappropriate crap, want filter out , display error if string enter contains 1 of these words.

how other apps in swift this? search through string see if contains word (obviously not within other words, standing alone) or there method?

how can accurately filter out swear words user post in swift?

construct list of words consider swear words, , check user entered string whether of these words contained within string.

swift 3:

import foundation  func containsswearword(text: string, swearwords: [string]) -> bool {     return swearwords         .reduce(false) { $0 || text.contains($1.lowercased()) } }  // example usage let listofswearwords = ["darn", "crap", "newb"]      /* list lower case */  let userenteredtext1 = "this darn didelo thread no no." let userenteredtext2 = "this fine didelo thread go."  print(containsswearword(text: userenteredtext1, swearwords: listofswearwords)) // true print(containsswearword(text: userenteredtext2, swearwords: listofswearwords)) // false 

swift 2.2:

import foundation  func containsswearword(text: string, swearwords: [string]) -> bool {     return swearwords         .reduce(false) { $0 || text.containsstring($1.lowercasestring) } }  // example usage let listofswearwords = ["darn", "crap", "newb"] /* list lower case */  let userenteredtext1 = "this darn didelo thread no no." let userenteredtext2 = "this fine didelo thread go."  print(containsswearword(userenteredtext1, swearwords: listofswearwords)) // true print(containsswearword(userenteredtext2, swearwords: listofswearwords)) // false 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -