There are several ways to determine whether one string is a substring of another. The following way is probably the simp
Posted: Wed Apr 27, 2022 3:48 pm
There are several ways to determine whether one string is a substring of another. The following way is probably the simplest. Suppose we declare.
SUBl DB 'ABC'
MAINST DB 'ABABCA'
and we want to see whether SUB1 and SUB2 arc substrings of MAINST. Let's begin with SUB1. We can compare corresponding characters in the strings.
Because 'there is a mismatch at the third comparison, we backtrack and try to match SUBl with the part of MAINST from position MAINST+l on:
Q3. Write a program to check whether the one string is substring of another string usin procedures. ( 20 Marks) There are several ways to determine whether one string is a substring of another. The following way is probably the simplest. Suppose we declare. SUBI DB 'ABC MAINST DB 'ABABCA' and we want to see whether SUB1 and SUB2 arc substrings of MAINST. Let's begin with SUB1. We can compare corresponding characters in the strings. SUBI ABC MAINST і в Ався Because there is a mismatch at the third comparison, we backtrack and try to match SUB with the part of MAINST from position MAINST+I on: SUBT MAINST 1 A BABCA There is a mismatch immediately, so we begin again, and at position MAINST+2 SUB1 ABC MAINST А в Авс А This time we are successful; SUBI is a substring of MAINST Here is an Algorithm for Substring checking.
Algorithm for Substring Search Prompt user to enter SUBST Road SUBST Prompt use: to enter MAINST Hrad MAINST IF (length of MAINST is 0) OR (length of suast is o) OK (SUBST 45 longer than MAINST) THEN SUBST is not a substring of MAINST ELSE compute STOP START - ofiset of MAINST REPEAT compare corresponding characters in MAINST (from START on) and SUBST IF all characters match THEN SUBST found in MAINST ELSE START - START + 1 END IF UNTIL (SUPST found in MAINST) OP (START > STOP) Display results Test Case: C>PGM11_5 ENTER SUBST ABC ENTER MAINST XYZABABC SUBST IS A SUBSTRING OF MAINST C>PGM11_5 ENTER 9UBST ABD ENTEK MAINST ABACADACD SUBST IS NOT A SUBSTRING OF MAINST
SUBl DB 'ABC'
MAINST DB 'ABABCA'
and we want to see whether SUB1 and SUB2 arc substrings of MAINST. Let's begin with SUB1. We can compare corresponding characters in the strings.
Because 'there is a mismatch at the third comparison, we backtrack and try to match SUBl with the part of MAINST from position MAINST+l on:
Q3. Write a program to check whether the one string is substring of another string usin procedures. ( 20 Marks) There are several ways to determine whether one string is a substring of another. The following way is probably the simplest. Suppose we declare. SUBI DB 'ABC MAINST DB 'ABABCA' and we want to see whether SUB1 and SUB2 arc substrings of MAINST. Let's begin with SUB1. We can compare corresponding characters in the strings. SUBI ABC MAINST і в Ався Because there is a mismatch at the third comparison, we backtrack and try to match SUB with the part of MAINST from position MAINST+I on: SUBT MAINST 1 A BABCA There is a mismatch immediately, so we begin again, and at position MAINST+2 SUB1 ABC MAINST А в Авс А This time we are successful; SUBI is a substring of MAINST Here is an Algorithm for Substring checking.
Algorithm for Substring Search Prompt user to enter SUBST Road SUBST Prompt use: to enter MAINST Hrad MAINST IF (length of MAINST is 0) OR (length of suast is o) OK (SUBST 45 longer than MAINST) THEN SUBST is not a substring of MAINST ELSE compute STOP START - ofiset of MAINST REPEAT compare corresponding characters in MAINST (from START on) and SUBST IF all characters match THEN SUBST found in MAINST ELSE START - START + 1 END IF UNTIL (SUPST found in MAINST) OP (START > STOP) Display results Test Case: C>PGM11_5 ENTER SUBST ABC ENTER MAINST XYZABABC SUBST IS A SUBSTRING OF MAINST C>PGM11_5 ENTER 9UBST ABD ENTEK MAINST ABACADACD SUBST IS NOT A SUBSTRING OF MAINST