0% found this document useful (0 votes)
6 views12 pages

Stringoperation 140521042534 Phpapp01

The document discusses string operations in data structures and algorithms, including character sets, storage methods (fixed-length, variable-length, and linked storage), and various string operations such as length, substring, indexing, concatenation, insertion, deletion, and replacement. It also touches on pattern matching as a common problem in word processing. Examples are provided for each operation to illustrate their usage.

Uploaded by

PARDEEP MITTAL
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views12 pages

Stringoperation 140521042534 Phpapp01

The document discusses string operations in data structures and algorithms, including character sets, storage methods (fixed-length, variable-length, and linked storage), and various string operations such as length, substring, indexing, concatenation, insertion, deletion, and replacement. It also touches on pattern matching as a common problem in word processing. Examples are provided for each operation to illustrate their usage.

Uploaded by

PARDEEP MITTAL
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

String Operation

Csc-391
Data Structures and Algorithms
2

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


Data Structures and Algorithms
3

Storing String
• For Example,

©SMT, Faculty, CSE, IUBAT


Data Structures and Algorithms
4

Storing String
• 1. Fixed- length storage.

©SMT, Faculty, CSE, IUBAT


Data Structures and Algorithms
5

Storing String
• 1. Fixed- length storage.

©SMT, Faculty, CSE, IUBAT


Data Structures and Algorithms
6

Storing String
• 2. Variable- length storage with fixed maximum.

©SMT, Faculty, CSE, IUBAT


Data Structures and Algorithms
7

Storing String
• 2. Variable- length storage with fixed maximum.

©SMT, Faculty, CSE, IUBAT


Data Structures and Algorithms
8

Storing String
• 3. Linked storage

©SMT, Faculty, CSE, IUBAT


Data Structures and Algorithms
9

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


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

©SMT, Faculty, CSE, IUBAT


Data Structures and Algorithms
11

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


Data Structures and Algorithms
12

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

You might also like