From: Phlip Date: 2003-01-05T02:36:08+09:00 Subject: Re: object You could think of a better Subject here... Manfred Hansen wrote: > i have the following script: > > werte = "anfang=123&ende=was" > > werte.split(/&/).each do |x| > key, val = x.split(/=/,2) > puts "key = #{key} , val = #{val}" > end > > puts anfang # => 123 > > The goal is when i make puts anfang to get the value "123". > The problem is the values from werte can be changed > for example: > werte = "irgendwas=hu&ruby=super" > > Now i will make puts irgendwas => hu > And so on. > > Is this possible? Here's the relevant code from MiniRubyWiki: def decodeURL post result = {} post.split('&').each do |token| token = CGI::unescape(token) key, value = token.split(/=/, 2) result[key] = value end return result end The outer splitter breaks on the & partitions, and the inner splitter breaks on the =. Then the method returns everyone in one big happy map. If you are using CGI, you'l need the 'CGI::unescape' to turn %20 into space, etc. -- Phlip http://www.greencheese.org/SkeletonCrew -- Got in trouble at StarBucks. I tried to order "A double latte mocha and a body piercing." --