Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #58754
| From | Ron Aaron <rambamist@gmail.com> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: excercise from Robert L, please comment |
| Date | 2017-05-07 07:46 +0300 |
| Organization | A noiseless patient Spider |
| Message-ID | <oem8ki$ud5$1@dont-email.me> (permalink) |
| References | <oekb0j$f1b$1@dont-email.me> <oeknb6$ml6$1@dont-email.me> |
If you're willing to consider alternatives to ANS Forth, here's a solution in 8th: \ String 'C6 H12 O6' that I wish to split up to give 2 strings \ 'C H O' and '6 12 6'." \ Split the string on spaces: "C6 H12 O6" " " s:/ \ For each string in the resultant array, split into head and tail "" \ empty result of first concat "" \ empty result of second concat rot \ get the array into position ( \ stack is: "first" "second" index string \ we dont' need the index nip \ split the string into head and tail 1 s:/ a:open \ put the tail onto 'second' rot swap s:+ " " s:+ \ do the same for the first >r s:+ " " s:+ r> ) a:each drop \ We added an unneeded space at the end of both strings, so get rid of it: s:trim swap s:trim . cr . cr bye The result is: C H O 6 12 6 Of course there are other ways to accomplish the goal. I could have used regular-expressions, or I could have iterated the string directly.
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
excercise from Robert L, please comment Andreas Klimas <klimas@w3group.de> - 2017-05-06 13:14 +0200
Re: excercise from Robert L, please comment Alex <alex@rivadpm.com> - 2017-05-06 13:14 +0100
Re: excercise from Robert L, please comment Andreas Klimas <klimas@w3group.de> - 2017-05-06 16:44 +0200
Re: excercise from Robert L, please comment Alex <alex@rivadpm.com> - 2017-05-06 19:55 +0100
Re: excercise from Robert L, please comment Alex <alex@rivadpm.com> - 2017-05-06 20:26 +0100
Re: excercise from Robert L, please comment Andreas Klimas <klimas@w3group.de> - 2017-05-07 23:08 +0200
Re: excercise from Robert L, please comment Ron Aaron <rambamist@gmail.com> - 2017-05-07 07:46 +0300
Re: excercise from Robert L, please comment Ron Aaron <rambamist@gmail.com> - 2017-05-07 07:54 +0300
Re: excercise from Robert L, please comment hughaguilar96@gmail.com - 2017-05-07 09:15 -0700
Re: excercise from Robert L, please comment humptydumpty <ouatubi@gmail.com> - 2017-05-08 11:00 -0700
Re: excercise from Robert L, please comment humptydumpty <ouatubi@gmail.com> - 2017-05-08 11:52 -0700
Re: excercise from Robert L, please comment "HAA" <someone@microsoft.com> - 2017-05-09 13:20 +1000
Re: excercise from Robert L, please comment humptydumpty <ouatubi@gmail.com> - 2017-05-10 00:26 -0700
Re: excercise from Robert L, please comment "HAA" <someone@microsoft.com> - 2017-05-11 17:07 +1000
Re: excercise from Robert L, please comment humptydumpty <ouatubi@gmail.com> - 2017-05-11 00:25 -0700
Re: excercise from Robert L, please comment Julian Fondren <julian.fondren@gmail.com> - 2017-05-08 21:40 -0700
Re: excercise from Robert L, please comment Julian Fondren <julian.fondren@gmail.com> - 2017-05-08 21:46 -0700
csiph-web