View previous topic :: View next topic |
Author |
Message |
Rahull Beginner
Joined: 29 Jan 2004 Posts: 62 Topics: 19
|
Posted: Thu Sep 08, 2005 12:53 pm Post subject: Solution required # 1 |
|
|
Hi,
Problem#1
I have 3 alpha numeric variables of 100 bytes to store name.
Var 1 Pic x(100). (For first name)
Var 2 Pic x(100). (for middle name)
Var 3 Pic x(100). (for last name)
(Any name can have spaces in between. i.e. First name can be "Raja ram".)
I have only one output variable of 40 bytes where i need to store the complete name. (Each part of name will be followed by one space)
Case : If sum of length of first + second + last > 40. Try to get complete first and last name and truncate second name.
Always length first + last name < or = 40.
Please suggest me how to do it in easy way. What solution I thought of so far is to use pointer for first and second and last name using STRING comnad.
Please provide some pseudo code if possible.
Problem # 2 :
I have address stored in one varaible of 100 bytes. I need to split the complete address in 5 lines of 20 bytes each in a very smart way.
For eg:
Var1 :: 3223, Apt # C, hartford road, hardford, connecticut.
output 1 : 3223, Apt # C
Output 2: Hartford road
.
.
( Smart logic: if the 20 th bytes does not end in space then I dont want that WORD of address part in that line)
Please suggest and provide pseudocode |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12372 Topics: 75 Location: San Jose
|
Posted: Thu Sep 08, 2005 1:33 pm Post subject: |
|
|
Quote: |
Problem:1
Please suggest me how to do it in easy way. What solution I thought of so far is to use pointer for first and second and last name using STRING comnad.
Please provide some pseudo code if possible.
|
Please search before posting. There have been several discussions about finding the actual length of string. Please search for "length" in application programming forum, you will find many examples.
Quote: |
( Smart logic: if the 20 th bytes does not end in space then I dont want that WORD of address part in that line)
|
Define the string as an array and check the 20th byte for a space. If it is not a space then use perform varying backwards untill you find a space
Hope this helps...
Cheers
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
ofer71 Intermediate
Joined: 12 Feb 2003 Posts: 358 Topics: 4 Location: Israel
|
Posted: Fri Sep 09, 2005 3:10 pm Post subject: |
|
|
Here is a REXX solution to problem 1:
Code: |
/* REXX */
FIRST = 'FIRST NAME'
MID = 'THIS_IS_JUST_A_VERY_LONG_STRING'
LAST = 'LAST NAME'
SAY FULL(FIRST, MID, LAST)
EXIT
FULL:
F = STRIP(SPACE(ARG(1),1))
M = STRIP(SPACE(ARG(2),1))
L = STRIP(SPACE(ARG(3),1))
IF LENGTH(F) + LENGTH(M) + LENGTH(L) <= 40 THEN
RETURN F M L
ELSE
RETURN F SUBSTR(M,1,38-(LENGTH(F)+LENGTH(L))) L
|
O.
________
AMX-GT |
|
Back to top |
|
|
|
|