String operation
-
Upload
shakila-mahjabin -
Category
Education
-
view
194 -
download
2
description
Transcript of String operation
![Page 1: String operation](https://reader034.fdocuments.net/reader034/viewer/2022052505/55665ef4d8b42a3d3f8b45ad/html5/thumbnails/1.jpg)
String Operation
Csc-391
![Page 2: String operation](https://reader034.fdocuments.net/reader034/viewer/2022052505/55665ef4d8b42a3d3f8b45ad/html5/thumbnails/2.jpg)
2
Data Structures and Algorithms
Remarks
• Each programming language contains a character set that is used to communicate with the computer. This set usually includes the followings-
• Alphabet- A B C D… X Y Z
• Digits- 0 1 2.. 9
• Special Characters- + - / * . (), {}, , $ etc..
©SMT, Faculty, CSE, IUBAT
![Page 3: String operation](https://reader034.fdocuments.net/reader034/viewer/2022052505/55665ef4d8b42a3d3f8b45ad/html5/thumbnails/3.jpg)
3
Data Structures and Algorithms
Storing String
• For Example,
©SMT, Faculty, CSE, IUBAT
![Page 4: String operation](https://reader034.fdocuments.net/reader034/viewer/2022052505/55665ef4d8b42a3d3f8b45ad/html5/thumbnails/4.jpg)
4
Data Structures and Algorithms
Storing String• 1. Fixed- length storage.
©SMT, Faculty, CSE, IUBAT
![Page 5: String operation](https://reader034.fdocuments.net/reader034/viewer/2022052505/55665ef4d8b42a3d3f8b45ad/html5/thumbnails/5.jpg)
5
Data Structures and Algorithms
Storing String• 1. Fixed- length storage.
©SMT, Faculty, CSE, IUBAT
![Page 6: String operation](https://reader034.fdocuments.net/reader034/viewer/2022052505/55665ef4d8b42a3d3f8b45ad/html5/thumbnails/6.jpg)
6
Data Structures and Algorithms
Storing String• 2. Variable- length storage with fixed maximum.
©SMT, Faculty, CSE, IUBAT
![Page 7: String operation](https://reader034.fdocuments.net/reader034/viewer/2022052505/55665ef4d8b42a3d3f8b45ad/html5/thumbnails/7.jpg)
7
Data Structures and Algorithms
Storing String• 2. Variable- length storage with fixed maximum.
©SMT, Faculty, CSE, IUBAT
![Page 8: String operation](https://reader034.fdocuments.net/reader034/viewer/2022052505/55665ef4d8b42a3d3f8b45ad/html5/thumbnails/8.jpg)
8
Data Structures and Algorithms
Storing String• 3. Linked storage
©SMT, Faculty, CSE, IUBAT
![Page 9: String operation](https://reader034.fdocuments.net/reader034/viewer/2022052505/55665ef4d8b42a3d3f8b45ad/html5/thumbnails/9.jpg)
9
Data Structures and Algorithms
String Operation• Length: LENGTH (string)
e.g.- LENGTH(‘Mark Zuckerberg’)= 15
• Substring: SUBSTRING(string, initial, length)
e.g.- SUBSTRING(‘Impossible is a word found in coward’s dictionary’,0,20) = Impossible is a word
• Indexing: INDEX(string, pattern)
e.g.- INDEX(‘He is wearing glasses’, ‘ear’)= 8
• Concatenation: String1//String2
e.g.- ‘To be or not to be’// ‘, this is the question.’= To be or not to be, this is the question
©SMT, Faculty, CSE, IUBAT
![Page 10: String operation](https://reader034.fdocuments.net/reader034/viewer/2022052505/55665ef4d8b42a3d3f8b45ad/html5/thumbnails/10.jpg)
©SMT, Faculty, CSE, IUBAT
String Operation
• Word Processing-
Insertion: INSERT(string, position, string)e.g.- INSERT(‘ABCDEIJKL’,5,‘FGH’)= ABCDEFGHIJKL
Deletion: DELETE(string, position, length)e.g.- DELETE(‘ABCDEFG’, 4, 2)= ABCDG
![Page 11: String operation](https://reader034.fdocuments.net/reader034/viewer/2022052505/55665ef4d8b42a3d3f8b45ad/html5/thumbnails/11.jpg)
11
Data Structures and Algorithms
String Operation– Replacement: REPLACE(string, pattern1, pattern2)
e.g.- REPLACE(‘XABYABZ’, ‘AB’, ‘c’)= XCYABZ
REPLACE function can be executed be using the following three steps-
1. K:= INDEX(string, P1)
2. T:= DELETE(string, K, LENGTH(P1))
3. INSERT(T, K, P1)
– So, the algorithm is-
©SMT, Faculty, CSE, IUBAT
![Page 12: String operation](https://reader034.fdocuments.net/reader034/viewer/2022052505/55665ef4d8b42a3d3f8b45ad/html5/thumbnails/12.jpg)
12
Data Structures and Algorithms
String Operation– Pattern Matching:
Pattern matching is the problem of deciding whether or not a given string pattern P appears in a text.
Widely used in word processing.
– So, a basic algorithm is-
©SMT, Faculty, CSE, IUBAT