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
Well, anyway. Cheers! Stefan
Peter Buck (pb...@NSF.GOV) wrote:
: foo = translate(bar, "abc", "ABC") translates the first 3 chars. Enter full
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
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)
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".
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"
>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
>
> - seb
/ahw
/*
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.
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
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.