View previous topic :: View next topic
|
Author |
Message |
prabs2006
Active User
Joined: 12 Jan 2006 Posts: 103
|
|
|
|
Hi all,
I have a reqmt. I need all the first letter of a word (in a sentence) to be caps? H can I do that?
Eg: this is rexx
to be as
This Is Rexx
T & R
Prabs |
|
Back to top |
|
|
ofer71
Global Moderator
Joined: 27 Dec 2005 Posts: 2358 Location: Israel
|
|
|
|
Here is my CAPITAL rexx. It capitalize input, except string in quotes or double quotes:
Code: |
/****************************** REXX ******************************** */
/* */
/* Name.......: CAPITAL */
/* */
/* Function...: Capitalize a string. */
/* */
/* Date.......: 04/05/2003. */
/* */
/* Author.....: OFER */
/* */
/* Reqirements: - */
/* */
/* Description: Change the start of words to upper-case. All other */
/* letters are changed to lower-case. */
/* Call as a function: X = ACPITAL(string) */
/* */
/**********************************************************************/
ARG INPUT
DQ = 0
SQ = 0
OUTPUT = ""
PREV = ' '
UPPER = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 '
LOWER = 'abcdefghijklmnopqrstuvwxyz1234567890 '
DO I = 1 TO LENGTH(INPUT)
IF SUBSTR(INPUT,I,1) = "'" THEN
SQ = SQ + 1
IF SUBSTR(INPUT,I,1) = '"' THEN
DQ = DQ + 1
IF DATATYPE(PREV,"M") |,
(PREV = "'" & (SQ//2 = 0 | DQ//2 = 1)) |,
(PREV = '"' & (SQ//2 = 0 | DQ//2 = 1)) THEN
OUTPUT = OUTPUT||TRANSLATE(SUBSTR(INPUT,I,1),LOWER,UPPER)
ELSE
OUTPUT = OUTPUT||TRANSLATE(SUBSTR(INPUT,I,1),UPPER,LOWER)
PREV = SUBSTR(INPUT,I,1)
END
RETURN OUTPUT
|
O. |
|
Back to top |
|
|
prabs2006
Active User
Joined: 12 Jan 2006 Posts: 103
|
|
|
|
Thanks Ofer...but dont we have any inbuilt function?
T & R
Prabs |
|
Back to top |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
|
|
Yes, Parse Upper ... |
|
Back to top |
|
|
ofer71
Global Moderator
Joined: 27 Dec 2005 Posts: 2358 Location: Israel
|
|
|
|
PARSE UPPER will convert the whole string to uppercase. Prabs was asking about capitalization.
O. |
|
Back to top |
|
|
prabs2006
Active User
Joined: 12 Jan 2006 Posts: 103
|
|
|
|
Hi
can you please explain this condition from the above set of code posted by Ofer.
IF DATATYPE(PREV,"M") |,
(PREV = "'" & (SQ//2 = 0 | DQ//2 = 1)) |,
(PREV = '"' & (SQ//2 = 0 | DQ//2 = 1)) THEN
T & R
Prabs |
|
Back to top |
|
|
ofer71
Global Moderator
Joined: 27 Dec 2005 Posts: 2358 Location: Israel
|
|
|
|
This piece of code tells REXX: If we are not at the start of new word, and if we are not in the middle of a constant (bounded by quotes) - then translate to lowercase.
O. |
|
Back to top |
|
|
prabs2006
Active User
Joined: 12 Jan 2006 Posts: 103
|
|
|
|
Hi Ofer,
Sorry to bug u again. I can understand from higher level. It will be better if u can explain me explicitly. Thanks
T & R
Prabs |
|
Back to top |
|
|
ofer71
Global Moderator
Joined: 27 Dec 2005 Posts: 2358 Location: Israel
|
|
|
|
I reading the string char by char. When I encounter a quote or double quote, I add 1 to the counter.
The question in the IF says: If the number of quotes is even (that means - we are not in the middle of a constant), then translate to lowercase.
O. |
|
Back to top |
|
|
prabs2006
Active User
Joined: 12 Jan 2006 Posts: 103
|
|
|
|
Thanks a lot buddy. I got it |
|
Back to top |
|
|
|