Message from discussion one-liner for characater replacement
From: "James Giles" <jamesgi...@worldnet.att.net>
Subject: Re: one-liner for characater replacement
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198
X-RFC2646: Format=Flowed; Original
Date: Sun, 18 May 2008 19:36:21 GMT
X-Trace: bgtnsc04-news.ops.worldnet.att.net 1211139381 18.104.22.168 (Sun, 18 May 2008 19:36:21 GMT)
NNTP-Posting-Date: Sun, 18 May 2008 19:36:21 GMT
Organization: AT&T Worldnet
> I want to replace every occurrence of a dash in a string by a space.
> Surely this can be done with a one-liner?
A very long and hard to read one-liner, sure. TRANSFER the string
to an array of character (you'll have to do this in two places: the TSOURCE
operand to MERGE, and inside the MASK expression to MERGE), use
MERGE (the FSOURCE operand is, of course, just a space character),
then use TRANSFER again to get the result back into the form of a string.
Unless the above is *very* much faster (or you can prove the code
using it is a *very* critical bottle-neck) you should prefer the more
legible simple scalar loop.
do i = 1, len(string)
if(string(i:i) == '-') String(i:i) = ' '
Of course, you *can* make that a one liner:
do i = 1, len(string); if(string(i:i) == '-') String(i:i) = ' '; end do
"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies." -- C. A. R. Hoare