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

From Coder Merlin
Line 1: Line 1:
== Print All Integers in a String  ==
= Print All Integers in a String  =
 
== Swift ==
<syntaxhighlight lang="swift">
<syntaxhighlight lang="swift">
var line : String?
var line : String?
Line 13: Line 15:
} while line != nil
} while line != nil
</syntaxhighlight>
</syntaxhighlight>
== Python ==

Revision as of 17:27, 24 December 2018

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

Print All Integers in a String[edit]

Swift[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

Python[edit]