Nicolas, Thanks. Verbose is fine. I will give your suggestion a try. I also commented on fernando's email below.
S. On Nov 15, 2011, at 3:26 AM, Nicolas Cellier wrote: > It might seem a bit verbose, but your example translates as > > aDictionary associations inject: string into: [:subst :assoc | assoc > key asRegex copy: subst replacingMatchesWith: assoc value]. > > Nicolas > > 2011/11/14 Fernando Olivero <[email protected]>: >> I dont fully understand your question, also i have no idea what #gsub does. gsub does a global search and replace in the string to replace any elements with the replacement text. mystring:='hello there hello' eg myString.gsub('hello','goodbye') ===> 'goodbye there goodbye' S. >> >> do you start from a dictionary ? or a string ? it seems that you want >> to create a dictionary from a particular string. >> >> Could you provide an example of such string, i could help you in >> finding the correct messages of String/Stream to send. >> >> The #gsub message, seems pertinent to all Strings? or is a special >> behavior for your special case? >> >> >> Fernando >> >> On Mon, Nov 14, 2011 at 10:17 AM, Sven Van Caekenberghe <[email protected]> >> wrote: >>> >>> On 14 Nov 2011, at 08:25, mail list wrote: >>> >>>> I have a dictionary of keys and values. >>>> >>>> I have a text string in which the keys are marked with before and ending >>>> symbols. >>>> >>>> In ruby to replace the key with the value in the text string is reasonably >>>> simple. (eg Dictionary.each { key,value | string.gsub!(key,value) } - or >>>> similar to this. >>>> >>>> While I don't mind rolling my version of this in Smalltalk, just exploring >>>> the regex code and the streams code it is not obvious where is the easiest >>>> place to start. >>>> >>>> If someone would put their comments on where to start I will build the >>>> functionality and put it up on squeaksource since I think it is common >>>> requirement. >>>> >>>> S. >>> >>> There is String>>#format: but there are probably other options as well. >>> >>> Sven >>> >> >> >
