COBOL - String Handling
String handling statements are used in COBOL to perform operations of string manipulation. COBOL provides three types of statements for string handling:
Inspect verb replaces or counts a character or a group of characters in a string. On numeric, alphabetic, or alphanumeric values, we can perform string operations. Inspect operations are work from left to right.
The Inspect provides two options are as follows:
Tallying is used to count the string characters.
Here, input-string and output string are parameters. Input-string is the string whose characters are to be counted. And output-string is data item to hold the count of characters.
Let's see an example for Tallying option:
Replacing option replaces the string characters.
Here, the input-string parameter is the string whose characters are to be replaced from char1 to char2.
The string verb is used to concatenate the partial or full contents of two or more string or literal into one single data item. In the String verb, the 'DELIMITED BY' clause is compulsory.
Here, used parameters details are:
Let's see an example for String verb:
The UNSTRING verb breaks one string into several sub-strings. The ' DELIMITED BY ' clause is mandatory in the unstring verb.
Let's see an example for Unstring verb: