COBOL - String HandlingString handling statements are used in COBOL to perform operations of string manipulation. COBOL provides three types of statements for string handling:
INSPECTInspect 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?Tallying is used to count the string characters. Syntax: 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. Example: Let's see an example for Tallying option: Output: ReplacingReplacing option replaces the string characters. Syntax: Here, the input-string parameter is the string whose characters are to be replaced from char1 to char2. Example: Output: STRINGThe 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. Syntax:Here, used parameters details are:
Example:Let's see an example for String verb: Output: UNSTRINGThe UNSTRING verb breaks one string into several sub-strings. The ' DELIMITED BY ' clause is mandatory in the unstring verb. Syntax:Example:Let's see an example for Unstring verb: Output: Next TopicArray/Table Processing |