Page 1 of 1

Delete any word from a sentence

PostPosted: Wed Sep 16, 2015 5:16 pm
by common_guy
Input string (that is a sentence) is of max 80 length characters.

user will give the word which need to be deleted.

Re: Delete any word from a sentence

PostPosted: Wed Sep 16, 2015 6:33 pm
by Robert Sample
Since you did not ask any questions nor indicate any issues, why did you post?

This is a pretty simple application of reference modification (or a table of characters). COBOL doesn't have any type of intrinsic search function but the logic is pretty straightforward.

Re: Delete any word from a sentence

PostPosted: Sun Sep 20, 2015 10:27 am
by common_guy
Actually, by using inspect we can replace any word by another word of the same length. But while deleting suppose

My sentence is :

"My school is the best."

I want to delete the word "school".

My output will be :

"My is the best."

How to do that? Please give any suggestion.

Re: Delete any word from a sentence

PostPosted: Sun Sep 20, 2015 5:08 pm
by Robert Sample
1. Count the characters in the word.
2. Find the word in your sentence.
3. Use reference modification (or an array) to move all characters up to your word to your output variable.
4. Use reference modification (or an array) to move all characters after your word to the correct location in your output variable.

If the word can occur more than once in the sentence, and each occurrence is to be deleted, then repeat steps 2 through 4 until you hit the end of the sentence (or at least until the word can no longer occur in the sentence). Key points: use an output variable instead of trying to do it in one variable; you'll need several variables for location and length; and you won't go wrong to run through a couple of examples with paper and pen to make sure you understand what the code is doing.