Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Lect 14 Zaheer Abbas


Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Lect 14 Zaheer Abbas

  1. 1. Created by Zaheer Abbas Aghani
  3. 3. Strings Operations <ul><li>As we know that a string may be viewed simply a sequence of characters or linear array of characters. </li></ul><ul><li>For processing with such array of characters various string operations have been developed which are not normally used with other kinds of arrays. </li></ul><ul><li>These operations are called string oriented operations. </li></ul><ul><li>Following are four basic string oriented operations. </li></ul><ul><li>Substring </li></ul><ul><li>Indexing </li></ul><ul><li>Concatenation </li></ul><ul><li>Length </li></ul>
  4. 4. SUBSTRING <ul><li>Group of consecutive elements in a string (such as word, phrases and sentences), called substring. </li></ul><ul><li>OR </li></ul><ul><li>Part of string is called subtring. </li></ul><ul><li>For example: </li></ul><ul><li> ‘ TO BE OR NOT TO BE’ is a string and ‘TO BE OR’ are substring </li></ul><ul><li>Accessing a substring from a given string requires three pieces of information. </li></ul><ul><li>The name of string or string itself. </li></ul><ul><li>The position of first character of substring and </li></ul><ul><li>The length of substring. </li></ul>
  5. 5. SUBSTRING CONT… <ul><li>We call this operation SUBSTRING, specifically we write: </li></ul><ul><li>SUBSTRING(String, initial, length) </li></ul><ul><li>Examples: </li></ul><ul><li>SUBSTRING(‘TO BE OR NOT TO BE’, 4,7) = ‘BE OR N’ </li></ul><ul><li>SUBSTRING(‘THE END’, 4,4) = ‘ END’ </li></ul><ul><li>Substring function is denoted in some programming languages as follows: </li></ul><ul><li>PL/1: SUBSTR(S,4,7) </li></ul><ul><li>FORTRAN: S(4:10) </li></ul><ul><li>PASCAL: COPY(S,4,7) </li></ul><ul><li>BASIC: MID$(S,4,7) </li></ul>
  6. 6. INDEXING <ul><li>Indexing, also called pattern matching refers to finding the position where a string pattern first appears in a given string text. </li></ul><ul><li>We call this function INDEX and we write as : </li></ul><ul><li>INDEX(text,pattern) </li></ul><ul><li>This function returns an integer value. </li></ul><ul><li>If the pattern appears, INDEX return its position else if pattern does not appear in the string text, the INDEX is assigned the value 0. </li></ul><ul><li>Example: </li></ul><ul><li>suppose T contain the text=‘HIS FATHER IS THE PROFESSOR’ then </li></ul><ul><li>INDEX(T,’THE’) returns 7 </li></ul><ul><li>INDEX(T,’THEN’) returns 0 </li></ul><ul><li>INDEX(T,’ THE ’) returns 14 </li></ul>
  7. 7. INDEXING CONT… <ul><li>The function INDEX denoted in some programming languages as follows: </li></ul><ul><li>PL/1: INDEX(text, pattern) </li></ul><ul><li>PASCAL: POS(Pattern, text) </li></ul>
  8. 8. CONCATENATION <ul><li>Concatenation means to add to the end, or to append. This function adds one string at the end of another string. </li></ul><ul><li>Concatenation function is denoted by // </li></ul><ul><li>For example: S 1 //S 2 where S 1 is first string and S 2 is second. </li></ul><ul><li>Example: suppose S1 = ‘DATA’ and S2=‘STRUCTURE’ </li></ul><ul><li> then </li></ul><ul><li>S1//S2=‘DATASTRUCTURE’ </li></ul><ul><li> but </li></ul><ul><li>S1//’ ‘//S2=‘DATA STRUCTURE’ </li></ul>
  9. 9. CONCATENATION CONT… <ul><li>Concatenation is denoted in some programming languages as follows: </li></ul><ul><li>PL/1: S1//S2 </li></ul><ul><li>FORTRAN: S1//S2 </li></ul><ul><li>BASIC: S1+S2 </li></ul><ul><li>C: strcat(S1,S2) </li></ul>
  10. 10. LENGTH <ul><li>The no of characters in a string is called its length. </li></ul><ul><li>We will write it as: </li></ul><ul><li>LENGTH(String) </li></ul><ul><li>Example: </li></ul><ul><li>LENGTH(‘COMPUTER’) returns 8 </li></ul><ul><li>Some of the programming languages denote Length function as follows: </li></ul><ul><li>PL/1: LENGTH(String) </li></ul><ul><li>BASIC: LEN(String) </li></ul><ul><li>PASCAL: LENGTH(String) </li></ul><ul><li>C: strlen(String) </li></ul>
  11. 11. WORD PROCESSING OPERATIONS <ul><li>In earlier times, character data processed by the computer mainly of data items, such as names and address. today the computer also processes printed matter, such as letters, articles and reports. This is called word processing. </li></ul><ul><li>Word processing can also be define as: </li></ul><ul><li>“ The creation, input, editing and formatting of documents and other text using software on a computer.” </li></ul><ul><li>The operations usually associated with the word processing are the following: </li></ul><ul><li>Insertion </li></ul><ul><li>Deletion: </li></ul><ul><li>Replacement: </li></ul>
  12. 12. INSERTION <ul><li>Inserting a string in the middle of the text. </li></ul><ul><li>EXAMPLE: </li></ul><ul><li>INSERT(text, Position, String) </li></ul><ul><li>INSERT(‘ABCDEFG’,3,’XYZ’)=‘ABXYZCDEFG’ </li></ul><ul><li>INSERT(‘ABCDEFG’,6,’XYZ’)= ‘ABCDEXYZFG’ </li></ul><ul><li>DELETION </li></ul><ul><li>Deleting a substring from the text which begins in position K and has length L. </li></ul><ul><li>EXAMPLE: </li></ul><ul><li>DELETE(text, position, length) </li></ul><ul><li>DELETE ( ‘ABCDEFG’,4,2) = ABCFG </li></ul><ul><li>DELETE(‘ABCDEFG’,0,4) = ABCDEFG </li></ul>
  13. 13. REPLACEMENT <ul><li>This function is used to replace the first occurrence of a Pattern P1, by the Pattern P2. </li></ul><ul><li>We will denote this operation by REPLACE. </li></ul><ul><li>Example: </li></ul><ul><li>REPLACE(text, P1,P2) </li></ul><ul><li>REPLACE(‘ABCDEFG’,’AB’,’C’) = CCDEFG. </li></ul><ul><li>REPLACE(‘XABYABZ’,’BA’,’C’) = XABYABZ. </li></ul><ul><li>In second example, the pattern BA does not occur and hence there is no change. </li></ul>