brett s hallett's blog

Extracting and manipulation numbers from a text string

Tagged:  •    •    •    •  

Some years ago I came across a interesting text manipulation puzzle, on a c++ site
I think. I was learning Ruby at the time so had fun with implimenting in Ruby,
I decided to redo it in gst -- just for fun.

The problem: you have a string of mixed Alpha and Numeric characters, jumbled up,

'098m03r9f80239802389f0m9KDKL3KLJDKLJm0983m890DMOm003  dlkfj33hljf4h3klhl00000002998'.

We need to extract all the numerics, sort them into numeric order, but print them with leading zeros retained. Its not as obvious as it seems BTW. :-)

Randal Schwarts's challenge !

Reading Randal Schwarts' excellent comments, I had to take the last paragraph's challenge and rewrite his Squeak
solution into gst!.

" Randal Schwartz's modified md5 squeak code modified to gst"

 desiredLength := 20.
 sourceCharacterSet := '0123456789abcdefghijklmnopqrstuvwxyz'.
 str := String new: desiredLength.
 str := ((1 to: desiredLength) collect: [:each | sourceCharacterSet atRandom]) asString.
 str printNl.

Rewriting a script into a callable method

Tagged:  •  

After you have written your small test script and tested it interactively, it is often useful to convert it to a reusable method. The whole point about Methods is provide further modularization of your programs into more easily understood units of code.

Using the "Fun with MD5 and Random" example code posted on this blog by Samuel Montgomery October 3rd, 2007, as a starting point I wanted to use that routine as a callable method.

(Incidently 'method' is really another name for Procedure or Function in other languages)

Here is the original code : random.st

 | d i l s |

a text file processing example in gst

When first trying Smalltalk I always found it difficult to obtain simple complete programs to use as a reference tool. Smalltalkers just love showing code 'snippets', but learners need complete examples so they can see the total program. Hopefully this will be of use to somebody.

The Problem: I have a simple database system created & maintained by a REBOL program, which incidently is a very interesting GUI development language, and the collected data has to be imported into an existing MS-Access database,

Syndicate content

User login