View previous topic :: View next topic
|
Author |
Message |
meen
New User
Joined: 23 Jun 2008 Posts: 15 Location: bangalore
|
|
|
|
My requirement is to Count the number of characters in a string. After counting I need to divide this string into small strings. Suppose after counting I got the number of characters as 95.. Now I need to divide this into strings of 10 characters each.
Pls suggest how to do this?
Thanks in Advance |
|
Back to top |
|
|
Ketan Varhade
Active User
Joined: 29 Jun 2009 Posts: 197 Location: Mumbai
|
|
|
|
Hi,
Use a perform vaying to move the 10 10 byte of the string and keep a diff counter for the lenght of the string you can achive the desired result
Hope this help
Ketan |
|
Back to top |
|
|
Pankaj Shrivastava Currently Banned New User
Joined: 24 Jul 2009 Posts: 51 Location: Pune
|
|
|
|
Calculate the lenght of string first :
PERFORM VARYING var FROM length_of_string BY -1 UNTIL var < 1 OR string(var:1) NOT = SPACE
CONTINUE
END-PERFORM
DIVIDE length_of_string BY 10 GIVING length_of_string
REMAINDER WS-rem
If ws-rem not equal to zero
compute length_of_string = length_of_string +1
end-if
Define the splited vars with OCUURS clause in working storage as :
01 string pic x(99).
01 var-split redefines var pic x(99).
05 ws-split occurs 0 to 10 times depending on length_of_string .
10 ws-split-var pic x(10). |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
My requirement is to Count the number of characters in a string. After counting I need to divide this string into small strings. Suppose after counting I got the number of characters as 95.. Now I need to divide this into strings of 10 characters each.
Pls suggest how to do this? |
Your requirements are not clear enough to me to make suggestions. How long is the variable you're calling "a string" (not a standard COBOL term for a variable, by the way)? If the length is 1000 bytes and you're got 95 bytes scattered every 10 bytes or so, do you still want 10 outputs or 100 outputs? Do spaces count as characters in your requirement? Since COBOL does not allow variables to be undefined, pretty much by definition your variable will be fully populated with something -- SPACES, LOW-VALUES, junk data, or actual data. |
|
Back to top |
|
|
|