I've tested this little piece of code. As far as I can tell it works. If anyone can find anything wrong with this solution, let me know by sending an email to gte057t@prism.gatech.edu or bigqtip@cc.gatech.edu Christopher Henke
Okay, the previous posting of code contained pipes around tokenList and hexNumberList to declare them as temporary variables. Since the pipes are for tables, the code didn't show well. Edit the page and coping the code from there. Christopher Henke
Christopher, did you try anyone else's solution? Like Alfred's? Mark Guzdial
Question about this code: What is the first line doing? I keep getting an error when I try compiling. Shouldn't it be an arguement block?
Nadia
(aString findTokens: ' ')returns an ordered collection of tokens delimeted by a ' '(space) so it is an ordered collection of strings. "collect: [:token|token asInteger hex]" performs a collect operation on that ordered collection where for each of the elements in the collection, it will do an "asInteger" message to it and then to that it will to a "hex" message. I tried the code and I think "asInteger" should be "asNumber" or else you get an error. Pretty concise code. Philip Holly
Since it's a method do we have to put it in a block like this:
stringToHex:= [ :myString|
(myString findTokens: ' ') collect: [:token |token asNumber hex]
].
It seems to me like Chris's solution is the kind of thing I would be able to do in a test situation. I, for one, don't know how the collect: message works off the top of my head. I will probably look it up now that i saw it here, but using only the hints for information on what understand what messages, I would have formed something like Chris's answer
a _'15 12 13 14'.
myCollection _ OrderedCollection new.
str _a findTokens:( Character space asString).
oc _ str do:[:each |
myCollection add:((((each asNumber)asInteger)asHexDigit)asString)].
Oops....underscores!!!:
a :='15 12 13 14'.
myCollection :=OrderedCollection new.
str :=a findTokens:( Character space asString).
oc := str do:[:each |
myCollection add:((((each asNumber)asInteger)asHexDigit)asString)].
dat car alarm
Link to this Page
Fall 2001 Midterm Review last edited on 18 September 2001 at 11:31 am by w204d200.lawn.gatech.edu