Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Parsing problem

From: carl:cybercraft at: 14-Nov-2002 19:35

On 15-Nov-02, Blackeye Silverseeker wrote:
> Hello, i am new to rebol and i have a parsing problem. If somebody > could help me, i'd be grateful. Here is the code : > url: "www.asdfasdf.com:123/path/path/file.htm" parse/all url [ copy > host [ [to ":" skip copy port to "/" ] | [ to "/"]] copy path to end > ] > the goal is to have the words: > host = www.asdfasdf.com > port = 80 > path = path/path/file.htm > but the host word get the value: www.asdfasdf.com:80 > I tried many thins but i have now no idea of the solution. > Tank you
Hi, umm, Blackeye, (: Parse is probably overkill for what you're trying to do there, as there's a word (decode-url) to break up URLs into their various parts. The url does need an http:// though. Anyway, using your example, this is what decode-url gives (at the REBOL Console)...
>> url: join http:// "www.asdfasdf.com:123/path/path/file.htm"
== http://www.asdfasdf.com:123/path/path/file.htm
>> url-obj: decode-url url
decode-url has created an object there which can be looked at with probe...
>> probe url-obj
make object! [ user: none pass: none host: "www.asdfasdf.com" port-id: 123 path: "path/path/" target: "file.htm" ] as well as being accessed and changed in the normal way...
>> url-obj/host
== "www.asdfasdf.com"
>> url-obj/port-id
== 123
>> join url-obj/path url-obj/target
== "path/path/file.htm"
>> url-obj/port-id: 80
== 80
>> probe url-obj
make object! [ user: none pass: none host: "www.asdfasdf.com" port-id: 80 path: "path/path/" target: "file.htm" ] HTH. -- Carl Read