Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Translate to LOWER CASE in REXX?

1,538 views
Skip to first unread message

Deutscher

unread,
Dec 14, 1994, 12:27:55 PM12/14/94
to
Hi,
I am looking to write something in REXX that translates strings to LOWER CASE
(i.e. lower case <g>) if they are not mixed case.
(Want to write a script that changes all file names on my OS/2 machine to lower
case unless they are mixed already).
Now -- is there any more elegant way than parsing the string element by element
and converting asc->dec, subtracting whatever base I have in ASCII (or adding)
and converting back?
I understand that the mainframe days caused TRANSLATE UPPER to happen, but what
about me? Cheers! Stefan

Peter Buck

unread,
Dec 14, 1994, 2:13:49 PM12/14/94
to
foo = translate(bar, "abc", "ABC") translates the first 3 chars. Enter full
alphabet for full translation. This should be the default but as you say
grandfather mainframe defies logic.

As for preserving mixed case...hmm...bummer!
______________________________ Reply Separator _________________________________
Subject: Translate to LOWER CASE in REXX?
Author: General REXX Discussion List <REXX...@vm.gmd.de> at NOTE
Date: 12/14/94 1:40 PM

Rodger Bagnall

unread,
Dec 14, 1994, 3:44:01 PM12/14/94
to
On Wed, 14 Dec 1994 12:27:55 -0500 Deutscher said:
>Hi,
> I am looking to write something in REXX that translates strings to LOWER CASE
>(i.e. lower case <g>) if they are not mixed case.
>(Want to write a script that changes all file names on my OS/2 machine to lower
>case unless they are mixed already).
/* */
lc = 'abcdefghijklmnopqrstuvwxyz'
uc = translate(lc)
parse arg fn
if translate(fn) = fn then fn = translate(fn, lc, uc)
say fn

Deutscher

unread,
Dec 14, 1994, 3:56:19 PM12/14/94
to
I was afraid that this is it. Well, imagine we'd be in China and had to enter
the whole alphabet (or character set?? Does Chinese have a lower case at all?
Hm.). I just don't seem to get that IBM3090-CMS-MVS-TSO feeling out of my
bones.
Mixed case shouldn't be too bad, there is the data type function. It just gets
messy when (since) I want to allow for non-characters, say, digits, underscores
and the whole works that are allowed in a file name in OS/2.

Well, anyway. Cheers! Stefan

Peter Buck (pb...@NSF.GOV) wrote:
: foo = translate(bar, "abc", "ABC") translates the first 3 chars. Enter full

Jamie Hoglund

unread,
Dec 14, 1994, 7:28:49 PM12/14/94
to
In article <3cn9ur$m...@martha.utk.edu>,

s...@martha.utcc.utk.edu (Deutscher) wrote:
> Hi,
> I am looking to write something in REXX that translates strings to
> LOWER CASE (i.e. lower case <g>) if they are not mixed case.
> Now -- is there any more elegant way than parsing the string element by
> element and converting asc->dec, subtracting whatever base I have in ASCII
> (or adding) and converting back?
> I understand that the mainframe days caused TRANSLATE UPPER to happen,
> but what about me?
> Cheers! Stefan

Stefan,
Try this:
If DATATYPE(String,"M") = 0 then
String = TRANSLATE(String,XRANGE("a","z"),XRANGE("A","Z"))

Let me know if it works.

Jamie
--
Everything really is stupidly simple.. -Traffic

Rich Greenberg

unread,
Dec 14, 1994, 7:37:55 PM12/14/94
to
In article <3cn9ur$m...@martha.utk.edu> s...@martha.utcc.utk.edu (Deutscher) writes:
>Hi,
> I am looking to write something in REXX that translates strings to LOWER CASE
>(i.e. lower case <g>) if they are not mixed case.
>(Want to write a script that changes all file names on my OS/2 machine to lower
>case unless they are mixed already).

Translate will do this. i.e.:

out = translate(in,'abc....xyz','ABC...XYZ')

(where the .... should be filled in with the rest of the alphabet.)
--
Rich Greenberg Work: TBA. Know anybody needing a VM guru?
N6LRT TinselTown, USA Play: ric...@netcom.com 310-649-0238
Pacific time. I speak for myself & my dogs only. Canines: Chinook & Husky(RIP)

Glen Little

unread,
Dec 14, 1994, 8:53:27 PM12/14/94
to
In <3cnm5j$s...@martha.utk.edu>, s...@martha.utcc.utk.edu (Deutscher) writes:
>I was afraid that this is it. Well, imagine we'd be in China and had to enter
>the whole alphabet (or character set?? Does Chinese have a lower case at all?
>Hm.). I just don't seem to get that IBM3090-CMS-MVS-TSO feeling out of my
>bones.
>Mixed case shouldn't be too bad, there is the data type function. It just gets
>messy when (since) I want to allow for non-characters, say, digits, underscores
>and the whole works that are allowed in a file name in OS/2.

If you don't want to type the list of letters, try this:
lower = xrange('a','z')
upper = translate(lower)
allLowerText = translate(text,lower,upper)
Any character that is not a letter is not affected by this, so digits and
underscores stay as they are.

>: I am looking to write something in REXX that translates strings to LOWER CASE
>: (i.e. lower case <g>) if they are not mixed case.
>: (Want to write a script that changes all file names on my OS/2 machine to lower
>: case unless they are mixed already).

I whipped something up for you, here it is:

------------------------------------------------------------------------------
/* Convert to lowercase */
lower= xrange('a','z')
upper = translate(lower)

driveRoot = 'c:\*'

call RxFuncAdd 'SysFileTree', 'RexxUtil', 'SysFileTree'
call sysFileTree driveRoot, 'list', 'bso'

do i = 1 to list.0
fullname = list.i
name = filespec('name',fullName)
if name = translate(name) then do
newName = translate(name,lower,upper)
'@ren "'fullname'" "'newName'"'
say fullname '--->' newName
end
end

say
say 'Done. All files converted to lowercase if not mixed already.'
------------------------------------------------------------------------------
Glen Little // gli...@bcsc02.gov.bc.ca // Vancouver, BC Canada
*** I speak only for myself! ***
No longer "fishers of men" but "quickeners of mankind".


Peter Flass

unread,
Dec 15, 1994, 9:21:43 AM12/15/94
to
On Wed, 14 Dec 1994 14:13:49 EST Peter Buck said:
>foo = translate(bar, "abc", "ABC") translates the first 3 chars. Enter full
>alphabet for full translation. This should be the default but as you say
>grandfather mainframe defies logic.
>

On the contrary, it's perfectly logical. If you're going to work in mixed case
you *DONT* want to blindly translate everything to lower. You almost need
AI to determine what to translate and what not - names for example.

>As for preserving mixed case...hmm...bummer!

>______________________________ Reply Separator
>_________________________________
>Subject: Translate to LOWER CASE in REXX?
>Author: General REXX Discussion List <REXX...@vm.gmd.de> at NOTE
>Date: 12/14/94 1:40 PM
>
>
>Hi,

> I am looking to write something in REXX that translates strings to LOWER CASE
>(i.e. lower case <g>) if they are not mixed case.
>(Want to write a script that changes all file names on my OS/2 machine to lower
>case unless they are mixed already).

>Now -- is there any more elegant way than parsing the string element by element
>and converting asc->dec, subtracting whatever base I have in ASCII (or adding)
>and converting back?
>I understand that the mainframe days caused TRANSLATE UPPER to happen, but what
>about me? Cheers! Stefan

--------
Peter Flass <FL...@LBDRSCS.BITNET>
Systems Programmer -- Team OS/2
NYS Legislative Bill Drafting Commission
1450 Western Avenue, 3rd floor
Albany, NY 12203
Voice:(518)458-5114 FAX:(518)458-5108

"Help stamp out slogans in signature files"

Stephen E. Bacher

unread,
Dec 19, 1994, 1:54:12 PM12/19/94
to
>If DATATYPE(String,"M") = 0 then
> String = TRANSLATE(String,XRANGE("a","z"),XRANGE("A","Z"))

>Let me know if it works.

It won't work on an EBCDIC machine like an IBM mainframe, because
there are characters between "A" and "Z" (e.g. right brace, backslash)
which will get translated against your wishes.

- seb

A. Harry Williams

unread,
Dec 19, 1994, 10:01:06 PM12/19/94
to
Except for OpenEdition, those characters would be not valid in filenames,
so it would probably still do what was originally requested(which was
specific to OS/2) Though the point is also important to remind ASCII bigots
constantly.

>
> - seb
/ahw

Lon C. Thomas, Jr

unread,
Dec 20, 1994, 5:28:06 AM12/20/94
to
The point about EBCDIC is quite true ... there are gaps that would
result in unwanted character translation. However, the test for
mixed case string would not let these strings (with right brace and
such) pass, and so the translate would not occur.

Here is our solution, in the form of a function, wrapped around
a test case.

/*
Various lower case stuff
*/
s.1 = 'ALKJSDFLKSAJDLFK'
s.2 = 'ISDJFS}LEIJF'
s.0= 2
do s = 1 to s.0
If datatype(s.s,"M") then do
Say 'Lower' s.s 'is' lower(s.s)
End
Else do
Say s.s 'is not a mixed case string'
End
End
Exit
LOWER: Procedure
Parse arg string
lower = 'abcdefghijklmnopqrstuvxyz'
upper = translate(lower)
Return translate(string, lower, upper)


Lon Thomas
Arcane Software Consulting, Inc.

Stephen E. Bacher

unread,
Dec 20, 1994, 9:21:47 AM12/20/94
to
>/*
> Various lower case stuff
>*/
>s.1 = 'ALKJSDFLKSAJDLFK'
>s.2 = 'ISDJFS}LEIJF'
>s.0= 2
>do s = 1 to s.0
> If datatype(s.s,"M") then do
> Say 'Lower' s.s 'is' lower(s.s)
> End
> Else do
> Say s.s 'is not a mixed case string'
> End
> End
>Exit
>LOWER: Procedure
> Parse arg string
> lower = 'abcdefghijklmnopqrstuvxyz'
> upper = translate(lower)
> Return translate(string, lower, upper)

One recommendation: Move the initial assignments to
"lower" and "upper" out of the LOWER procedure and add
"expose lower upper" to the "procedure" statement. That
way you avoid the overhead of setting variables and calling
TRANSLATE twice each time you invoke LOWER from the loop.

If you want to make LOWER an external (library) function
instead, or even if you don't, it's worth the effort to
hardcode the strings:

Return translate(string, ,
'abcdefghijklmnopqrstuvwxyz', ,
'ABCDEFGHIJKLMNOPQRSTUVWXYZ')

(You could write a REXX [X]EDIT macro to generate the
constant strings while editing this exec. :-)

- seb

HRGR...@bcsc02.gov.bc.ca

unread,
Dec 22, 1994, 10:33:42 AM12/22/94
to
In article <1994122014...@support4.draper.com>

"Stephen E. Bacher" <seb...@SUPPORT4.DRAPER.COM> writes:

>
> Return translate(string, ,
> 'abcdefghijklmnopqrstuvwxyz', ,
> 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
>
> - seb
I am wondering if there is any performance advantage to ordering the
characters in order of usage rather than alphabetically?
Would 'etsr..................qx' or some such be more efficient?

Bob

Not a 'spokesperson' or 'spokeperdaughter' of BCSC.

Regards,
Bob Granewall
BC Systems Corporation
(604) 252-3203

Peter Flass

unread,
Dec 23, 1994, 8:41:21 AM12/23/94
to
On Thu, 22 Dec 1994 07:33:42 PST <HRGR...@BCSC02.GOV.BC.CA> said:
>In article <1994122014...@support4.draper.com>
>"Stephen E. Bacher" <seb...@SUPPORT4.DRAPER.COM> writes:
>
>>
>> Return translate(string, ,
>> 'abcdefghijklmnopqrstuvwxyz', ,
>> 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
>>
>> - seb
>I am wondering if there is any performance advantage to ordering the
>characters in order of usage rather than alphabetically?
>Would 'etsr..................qx' or some such be more efficient?
>
I would assume REXX builds a translate table and hence the order
should be immaterial. I would also assume implementations may
differ.

peltl...@delphi.com

unread,
Dec 22, 1994, 7:11:09 PM12/22/94
to
<HRGR...@bcsc02.gov.bc.ca> writes:

>>
>> Return translate(string, ,
>> 'abcdefghijklmnopqrstuvwxyz', ,
>> 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
>>
>> - seb
>I am wondering if there is any performance advantage to ordering the
>characters in order of usage rather than alphabetically?
>Would 'etsr..................qx' or some such be more efficient?

Answer: This one is definitely implementation-dependent on the IBM 370
mainframe there is a single machine instruction that will do such a
translation on upto 256 characters at the time (the TR instruction takes
two operands: a variable length string to be translated upto 256 chars long
and a 256-byte translate table. Each slot in the translate table contains
the target byte for translation).
Don't know if IBM uses the TR instruction on TSO/E, CMS or 370 REXX compiler.
There are other ways of doing this which also would not be frequency
dependent.

My two cents worth

--
-----------------------------------------------------------------------
! Nanoo, nanoo ! PELT INDUSTRIES
! Mark from Ark ! Software Experts
! ! 1(800) 741-4322 or 1(303) 442-7700
! Markus Pelt-Layman ! FAX: 1(303) 442-3198
! ! 8027 N. 41st Street, Longmont, CO 80503
-----------------------------------------------------------------------

Rodger Bagnall

unread,
Dec 22, 1994, 8:36:39 PM12/22/94
to
On Thu, 22 Dec 1994 07:33:42 PST <HRGR...@BCSC02.GOV.BC.CA> said:
>I am wondering if there is any performance advantage to ordering the
>characters in order of usage rather than alphabetically?
>Would 'etsr..................qx' or some such be more efficient?

Apart from implementation details it would depend on the distribution
of characters in the input. 'etsr..' would be OK for English language
input but might not be best for OS/2 file names especially since they
often skip vowels.

0 new messages