0% found this document useful (0 votes)
41 views7 pages

PDF Content

This document discusses string operations in three sentences: Strings are one-dimensional arrays of characters that include a null character at the end, and various functions exist for string length, substring extraction, indexing, concatenation, insertion, deletion, replacement, and pattern matching. Common string operations include getting the length of a string, extracting substrings, finding the index of a pattern, concatenating strings, inserting and deleting characters at positions, and replacing patterns. Deletion of characters from a string at a given position and length can be accomplished by using the DELETE function on the string.

Uploaded by

Manan Lamba
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)
41 views7 pages

PDF Content

This document discusses string operations in three sentences: Strings are one-dimensional arrays of characters that include a null character at the end, and various functions exist for string length, substring extraction, indexing, concatenation, insertion, deletion, replacement, and pattern matching. Common string operations include getting the length of a string, extracting substrings, finding the index of a pattern, concatenating strings, inserting and deleting characters at positions, and replacing patterns. Deletion of characters from a string at a given position and length can be accomplished by using the DELETE function on the string.

Uploaded by

Manan Lamba
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

Preview

 String
– String is a simple array of chars (characters)

– String is one-dimensional array of char

– The null character ‘\0’ must be included at the end of String

– Various built-in functions are provided for String function

1
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’)= 7

• 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
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
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-
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-


Deletion: DELETE(string, position, length)
Algorithm for deletion -
Deletion example-

You might also like