Difference between revisions of "Code Snippet: Print All Integers in a String"
From Coder Merlin
NerdOfLinux (talk | contribs) |
|||
Line 17: | Line 17: | ||
== Python == | == Python == | ||
<syntaxhighlight lang="python"> | |||
string = input() | |||
for char in string: | |||
if char.isdigit(): | |||
print(char) | |||
</syntaxhighlight> | |||
[https://stackoverflow.com/a/354073/8292439 Source] |
Revision as of 18:05, 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]
string = input()
for char in string:
if char.isdigit():
print(char)