






Hotspots: Admin Pages | Turn-in Site |
Current Links: Case Final Project Summer 2007
Sum2002 Midterm Review: String to Hex
Edit Sum2002 Midterm Review: String to Hex here.
stringToHex: numberString
"takes in a string of numbers separated by spaces, and
returns an ordered collection of their hexadecimal
equivalents (each number gets converted to a separate
string)."
| integerCollection hexCollection |
integerCollection _ numberString findTokens: ' ' .
hexCollection _ OrderedCollection new .
(1 to: integerCollection size)
do: [ :index |
hexCollection add: (integerCollection at: index) asNumber hex .
] .
^ hexCollection .
- alan fay (emptyset@cc.gatech.edu)
| this is good, but you can do it in one line, without temporary variables. how? Shaggz |
stringToHex: numberString
"smalltalk h4X0r"
^ (numberString findTokens: ' ') collect: [ :element | element asNumber hex ] .
- alan fay (emptyset@cc.gatech.edu)
Link to this Page