I have an arbitrary string that contains letters and numbers. Suppose I need to derive the 5th and 7th characters from it, and if these characters are numbers, then bring them to the Int type. How to do it?
- Working with strings is written in any swift tutorial in great detail. With symbols too. What exactly is incomprehensible to you? - PinkTux
- someone seriously "incomprehensible essence of the question"? - Max Mikheyenko
|
2 answers
Well, like this
let str = "ABCDEF6" let seventhSymbol = str[str.index(str.startIndex, offsetBy: 6)] print("седьмой символ: \(seventhSymbol)") if let test:Int = Int(String(seventhSymbol)) { print("это цифра \(test)") } |
I don’t know the syntax of the language you need, but on a general example: Make a condition in a loop (If such an element number is n, then take a variable of type int and assign it a value somehow transfer from char to int ). Oh yeah, in the condition you can put a check on whether these are the numbers on the ASCII table.
|