Difference between revisions of "Code Snippet: Print All Integers in a String"

From Coder Merlin
(Created page with "var line : String? repeat { line = readLine() if let text = line { for character in text { if ("0" ... "9").contains(character) { p...")
 
Line 1: Line 1:
== Print All Integers in a String  ==
<syntaxhighlight lang="swift">
var line : String?
var line : String?
repeat {
repeat {
Line 10: Line 12:
     }
     }
} while line != nil
} while line != nil
</syntaxhighlight>

Revision as of 13:33, 7 December 2018

Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder

Print All Integers in a String[edit]

var line : String?
repeat {
    line = readLine()
    if let text = line {
        for character in text {
            if ("0" ... "9").contains(character) {
                print(character)
            }
        }
    }
} while line != nil