Your SlideShare is downloading. ×
Lect 14 Zaheer Abbas
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Lect 14 Zaheer Abbas

318

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
318
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

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

×