I have a textField. I get the text that the user entered and must check if there is a specific character in this text. How to get this character?
1 answer
The String has a contains method (_ :) ( https://developer.apple.com/documentation/swift/string/2893238-contains there is an example of use). Here is my example:
import Foundation let myString = "Hello World" let mySymbol = "W" if myString.contains(mySymbol) { // 袙袨孝 孝校孝 袩袪袨袠小啸袨袛袠孝 袩袪袨袙袝袪袣袗 袧袗袥袠效袠携 小袠袦袙袨袥袗 袙 小孝袪袨袣袝 print("小懈屑胁芯谢", mySymbol," 胁 褋褌褉芯泻械 锌褉懈褋褍褌褋褌胁褍械褌") } else { print("小懈屑胁芯谢", mySymbol," 胁 褋褌褉芯泻械 芯褌褋褍褌褋褌胁褍械褌") } Console output:
The character W in the line is present
If you change the mySymbol variable, for example, to s, then the console output is:
The s character in the line is missing
|