Eliminating hyphen in Strings
Posted: Tue Jun 08, 2010 12:28 am
Suppose I have a word as shown v-i-k-r-a-n-t and I want it as only vikrant eliminating hyphen '-' or any other special characters. How can I do this?
Mainframe Technical Support Forums
https://www.ibmmainframeforum.com/
Robert Sample wrote:Your program output isVIKRAV
The first problem with your code is that it is very specific to the data -- an extra dash in the data would completely change your results. And the problem statement was to remove hyphens "or other special characters" which your code does not do.
The second problem you have is that your variable is 13 bytes yet your subscripts are only one-byte variables. So X goes from 1 to 3 to 5 to 9 to ... 1 again since a one-byte variable won't ever be more than 9.
The problem statement provided is woefully inadequate. How long can the input variable be? Can it have numbers? if so, are numbers considered valid or invalid characters? What are the invalid characters?
COBOL is a compiled language. Before the compile, every variable must be defined to COBOL -- which includes the maximum length allowed. Unlike C and other languages, COBOL does not support dynamic manipulation of variables lengths at run time (although there is a loophole in the way COBOL handles LINKAGE SECTION variables). So you cannot decide the length of the variable at run time -- you must decide how long it can be when you compile the program.but,
The 80 is arbitrary in ur code ok it will do
but if i want to decide the length according to my input string?