Ok, I am new to smalltalk. I have tried browsing and searching for methods related to parsing and splitting file contents based on a delimiter, but I am not having much success. :( Old google is not helping either so I can only assume that I am missing something "obvious".
I am reading a tab delimited file into a string. I want to iterate through this string and split by tab, or any other defined value (, . | # tab, cr, etc.), delimiter into substrings which are assigned to a Collection (Array, Dictionary, Bag, etc.), or instant variables.
I was hoping there was going to be something like:
Bag := FileStream collect: [:x | split: crlf]. Dictionary := Bag collect: [:x | split: tab].
Does that make any sense? Basically create Bag with contents of FileStream split by crlf and then split Bag elements by tab into key value pairs.
Again, I am surprised by the lack of examples demonstrating to newbies how to perform basic operations such as this. I know it is not the smalltalk way of learning, but it does raise the bar for making progress. The language may be easy, but finding which methods to use to solve problems is a bit laborious.
Thanks in advance.
findTokens:escapedBy:
might helpful
Am 29.08.2009 um 15:48 schrieb r00t uk r00tuk@gmail.com:
Ok, I am new to smalltalk. I have tried browsing and searching for methods related to parsing and splitting file contents based on a delimiter, but I am not having much success. :( Old google is not helping either so I can only assume that I am missing something "obvious".
I am reading a tab delimited file into a string. I want to iterate through this string and split by tab, or any other defined value (, . | # tab, cr, etc.), delimiter into substrings which are assigned to a Collection (Array, Dictionary, Bag, etc.), or instant variables.
I was hoping there was going to be something like:
Bag := FileStream collect: [:x | split: crlf]. Dictionary := Bag collect: [:x | split: tab].
Does that make any sense? Basically create Bag with contents of FileStream split by crlf and then split Bag elements by tab into key value pairs.
Again, I am surprised by the lack of examples demonstrating to newbies how to perform basic operations such as this. I know it is not the smalltalk way of learning, but it does raise the bar for making progress. The language may be easy, but finding which methods to use to solve problems is a bit laborious.
Thanks in advance. _______________________________________________ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
Hi,
ru> I am reading a tab delimited file into a string. I want to ru> iterate through this string and split by tab, or any other defined ru> value (, . | # tab, cr, etc.), delimiter into substrings which are ru> assigned to a Collection (Array, Dictionary, Bag, etc.), or ru> instant variables.
String>>findTokens is your friend here.
And FileStream>>contentsOfEntireFile gets the whole file into a string before you find the tokens. But I'd prefer to read the file one line at a time into a collection of strings.
Cheers,
Herbert
On Saturday 29 Aug 2009 7:18:02 pm r00t uk wrote:
I am reading a tab delimited file into a string. I want to iterate through this string and split by tab, or any other defined value (, . | # tab, cr, etc.), delimiter into substrings which are assigned to a Collection (Array, Dictionary, Bag, etc.), or instant variables.
See String>linesDo: and its senders. For parsing a line into tokens, you can use findTokens:
Again, I am surprised by the lack of examples demonstrating to newbies how to perform basic operations such as this. I know it is not the smalltalk way of learning, but it does raise the bar for making progress.
Searching source code is quite easy in Squeak. In this case, I used (Alt+Shift+W) to bring up the message search tool and searched for "lines". Then I used senders/implementers to explore methods.
HTH .. Subbu
Thanks everyone for the replies. I have not had a chance to try it yet, but it was one of the methods that I had come across but was not sure if it was the "best" one to use.
2009/8/29 K. K. Subramaniam subbukk@gmail.com
On Saturday 29 Aug 2009 7:18:02 pm r00t uk wrote:
I am reading a tab delimited file into a string. I want to iterate
through
this string and split by tab, or any other defined value (, . | # tab,
cr,
etc.), delimiter into substrings which are assigned to a Collection
(Array,
Dictionary, Bag, etc.), or instant variables.
See String>linesDo: and its senders. For parsing a line into tokens, you can use findTokens:
Again, I am surprised by the lack of examples demonstrating to newbies how to perform basic operations such as this. I know it is not the smalltalk way of learning, but it does raise the bar for making progress.
Searching source code is quite easy in Squeak. In this case, I used (Alt+Shift+W) to bring up the message search tool and searched for "lines". Then I used senders/implementers to explore methods.
HTH .. Subbu _______________________________________________ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
beginners@lists.squeakfoundation.org