Q. 1: Describe different types of string operations.
Ans: String operation:
Sub string: Accessing a substring from a given string requires three pieces of information:
i.    The name of the string or the string itself.
ii.    The position of the first character of the substr5ing in the given string and
iii.    The length of the substring or the position of the last character of the substring.
We call this operation SUBSTRING. Specially, we write
                SUBSTRING (String, initial, length)
To denote the substring of a string S beginning in a position K and having a length L.
Example:
            SUBSTRING (‘TO BE OR NOT TO BE’, 4, 7) = ‘BE OR N’
Indexing: Indexing also called pattern matching, re4fers to finding the position where a string pattern P first appears in a given text T. We call this operation INDEX and write
                INDEX (text, pattern)
If the pattern P does not appear in the text T, then INDEX is assigned the value 0. The argument “text” and “pattern” can be either string constants or string variables.
Example:
            T = ‘HIS FATHER IS THE PROFESSIOR’
            Then, INDEX (T, ‘THE’), INDEX (T, ‘THEN’)
Have the values 7, 0 respectively.
Concatenation: Let S1 and S2 be strings. Recall that the concatenation of S1 and S2, which we denote by S1//S2, is the string consisting of the characters of S1 followed by the characters of S2.
Example:
        Suppose, S1 = ‘MARK’,
               And, S2 = ‘TWAIN’
        Then, S1//S2 = ‘MARKTWAIN’
        But, S1//’     ‘//S2 = ‘MARK TWAIN’   
Length: The number of characters in a string is called its length. We will write –
            LENGTH (string)
for the length of a given string.
Example:
    Thus LENGTH (‘COMPUTER’) = 8
        LENGTH (‘      ’) = 0
        LENGTH (‘’) = 0
Q. 2: Describe different types of word processing.
Ans: Word processing: The operations usually associated with word processing are the following:
a.    Insertion: Inserting a string in the middle of the text. Suppose in given text T, we want to insert a string S, so that S begins in position K. We denote this operation by
INSERT (text, position, string)
    For example, INSERT (‘ABCDEFG’, 3, ‘XYZ’) = ‘ABXYZCDEFG’
b.    Deletion: Deleting a string from the text. Suppose in a given text T we want to delete the substring which begins in position K and has length L. We denote this operation by
DELETE (text, position, length)
    For example, DELETE (‘ABCDEFG’, 4, 2) = ‘ABCFG’
c.    Replacement: Replacing one string in the text by another. Suppose in a given text T we want to replace the first occurrence of a pattern P1 by a pattern P2. We will denote this operation by
REPLACE (text, pattern1, pattern2)
    For example, REPLACE (‘XABYABZ’, ‘AB’, ‘C’) = ‘XCYABZ’


No comments:
Post a Comment