SlideShare a Scribd company logo
1 of 13
Strings
Basic Terminologies
Each programming language contains a character set that is used to
communicate with the computer, which usually includes:
▫ Alphabets: A –Z
▫ Digits: 0-9
▫ Special Characters: + - / * ( ) , . $ = ‘ whitespaces etc
▫ A finite sequence S of zero or more characters is called a String.
▫ The number of characters in a string is called its length.
▫ The string with zero characters is called the empty string or the null
string.
2
Examples
▫ String
‘DATA STRUCTURES’ //length - 15
‘HOW ARE YOU?’ //length – 12
‘ ‘ //length – 1
‘’ //length – 0
3
String Operations
Concatenation:
▫ Let S1 and S2 be two strings. The concatenation of S1 and S2, which
we denote by S1 || S2, is the string consisting of the characters of S1
followed by characters of S2.
▫ Eg: suppose S1= ‘MARK’ and S2= ‘TWAIN’ , Then
S1||S2= ‘MARKTWAIN’
And,
S1||’ ‘||S2= ‘MARK TWAIN’
4
String Operations
Substring:
▫ Given a string s of length N, a substring of s is a contiguous partition
of s that has length less than or equal to N.
Accessing a substring from a given string requires 3 pieces of information:
1. The name of the string or the string itself.
2. The position of the first character of the substring in the given string
3. The length of the substring or the position of the last character of the
substring.
5
▫ SUBSTRING(string, initial, length)
▫ Example:
▫ SUBSTRING(‘MARK TWAIN’,7,4) = ‘WAIN’
6
String Operations
Indexing
▫ Also called pattern matching
▫ Finding the position where a string pattern P first appears in a given
string text.
▫ INDEX(string, pattern)
▫ Example:
▫ S= ‘HIS FATHER IS THE PROFESSOR’, then
INDEX (S,’THE’) have the value 7.
7
String Operations
Length
▫ LENGTH(string)
▫ Example: LENGTH(‘COMPUTER’)=8
8
Pattern matching algorithm
▫ Pattern matching is the problem of deciding whether or not a given
string pattern P appears in a string text T.
▫ Assume that length of P doesn’t exceed length of T
▫ Brute Force algorithm/First Pattern matching algorithm.
9
10
⬥ Let us take P= ‘GO’ and T= ‘ALGORITHM’
⬥ So, R will be 2 and S will be 9
⬥ Initially K=1, and MAX = 8
⬥ K<=MAX, true -> step 3.
⬥ L= 1 to 2 repeat,
⬥ P[1]!=T[1], { that is G != A}
⬥ then K=2,
⬥ Now K<=MAX, true -> step 3
⬥ L=1 to 2 repeat,
⬥ P[1]!=T[2], G!=L, then K=3
⬥ Now K<=MAX, true step 3,
⬥ L=1 to 2 repeat,
⬥ P[1]=T[3], G=G TRUE,
⬥ L=2
⬥ P[2]=T[3+2-1]= P[2]=T[4] ie. O=O
⬥ Index=3 and Exit.
⬥ Now we’ve Index of P in T at location 3
11
Exercises
You have the string text T=‘AROUND THE GLOBE’
1. Find index of pattern ‘THE’ in T
2. Find index of pattern ‘HER’ in T
12
THANKS!
ANY QUESTIONS?
Feel free to contact!!!
13

More Related Content

Similar to Strings

C Programming Strings.docx
C Programming Strings.docxC Programming Strings.docx
C Programming Strings.docx
8759000398
 
CPSTRINGSARGAVISTRINGS.PPT
CPSTRINGSARGAVISTRINGS.PPTCPSTRINGSARGAVISTRINGS.PPT
CPSTRINGSARGAVISTRINGS.PPT
Sasideepa
 
Java căn bản - Chapter9
Java căn bản - Chapter9Java căn bản - Chapter9
Java căn bản - Chapter9
Vince Vo
 

Similar to Strings (20)

CP-STRING (1).ppt
CP-STRING (1).pptCP-STRING (1).ppt
CP-STRING (1).ppt
 
CP-STRING.ppt
CP-STRING.pptCP-STRING.ppt
CP-STRING.ppt
 
CP-STRING.ppt
CP-STRING.pptCP-STRING.ppt
CP-STRING.ppt
 
05 c++-strings
05 c++-strings05 c++-strings
05 c++-strings
 
String Matching (Naive,Rabin-Karp,KMP)
String Matching (Naive,Rabin-Karp,KMP)String Matching (Naive,Rabin-Karp,KMP)
String Matching (Naive,Rabin-Karp,KMP)
 
STRINGS IN PYTHON
STRINGS IN PYTHONSTRINGS IN PYTHON
STRINGS IN PYTHON
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
C Programming Strings.docx
C Programming Strings.docxC Programming Strings.docx
C Programming Strings.docx
 
String in programming language in c or c++
String in programming language in c or c++String in programming language in c or c++
String in programming language in c or c++
 
Lesson in Strings for C Programming Lessons
Lesson in Strings for C Programming LessonsLesson in Strings for C Programming Lessons
Lesson in Strings for C Programming Lessons
 
CPSTRINGSARGAVISTRINGS.PPT
CPSTRINGSARGAVISTRINGS.PPTCPSTRINGSARGAVISTRINGS.PPT
CPSTRINGSARGAVISTRINGS.PPT
 
BHARGAVISTRINGS.PPT
BHARGAVISTRINGS.PPTBHARGAVISTRINGS.PPT
BHARGAVISTRINGS.PPT
 
Java căn bản - Chapter9
Java căn bản - Chapter9Java căn bản - Chapter9
Java căn bản - Chapter9
 
Strings
StringsStrings
Strings
 
358 33 powerpoint-slides_6-strings_chapter-6
358 33 powerpoint-slides_6-strings_chapter-6358 33 powerpoint-slides_6-strings_chapter-6
358 33 powerpoint-slides_6-strings_chapter-6
 
stringsinpython-181122100212.pdf
stringsinpython-181122100212.pdfstringsinpython-181122100212.pdf
stringsinpython-181122100212.pdf
 
Chapter 9 - Characters and Strings
Chapter 9 - Characters and StringsChapter 9 - Characters and Strings
Chapter 9 - Characters and Strings
 
Python programming : Strings
Python programming : StringsPython programming : Strings
Python programming : Strings
 
Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programming
 
PPS_Unit 4.ppt
PPS_Unit 4.pptPPS_Unit 4.ppt
PPS_Unit 4.ppt
 

Recently uploaded

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Recently uploaded (20)

FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 

Strings

  • 2. Basic Terminologies Each programming language contains a character set that is used to communicate with the computer, which usually includes: ▫ Alphabets: A –Z ▫ Digits: 0-9 ▫ Special Characters: + - / * ( ) , . $ = ‘ whitespaces etc ▫ A finite sequence S of zero or more characters is called a String. ▫ The number of characters in a string is called its length. ▫ The string with zero characters is called the empty string or the null string. 2
  • 3. Examples ▫ String ‘DATA STRUCTURES’ //length - 15 ‘HOW ARE YOU?’ //length – 12 ‘ ‘ //length – 1 ‘’ //length – 0 3
  • 4. String Operations Concatenation: ▫ Let S1 and S2 be two strings. The concatenation of S1 and S2, which we denote by S1 || S2, is the string consisting of the characters of S1 followed by characters of S2. ▫ Eg: suppose S1= ‘MARK’ and S2= ‘TWAIN’ , Then S1||S2= ‘MARKTWAIN’ And, S1||’ ‘||S2= ‘MARK TWAIN’ 4
  • 5. String Operations Substring: ▫ Given a string s of length N, a substring of s is a contiguous partition of s that has length less than or equal to N. Accessing a substring from a given string requires 3 pieces of information: 1. The name of the string or the string itself. 2. The position of the first character of the substring in the given string 3. The length of the substring or the position of the last character of the substring. 5
  • 6. ▫ SUBSTRING(string, initial, length) ▫ Example: ▫ SUBSTRING(‘MARK TWAIN’,7,4) = ‘WAIN’ 6
  • 7. String Operations Indexing ▫ Also called pattern matching ▫ Finding the position where a string pattern P first appears in a given string text. ▫ INDEX(string, pattern) ▫ Example: ▫ S= ‘HIS FATHER IS THE PROFESSOR’, then INDEX (S,’THE’) have the value 7. 7
  • 8. String Operations Length ▫ LENGTH(string) ▫ Example: LENGTH(‘COMPUTER’)=8 8
  • 9. Pattern matching algorithm ▫ Pattern matching is the problem of deciding whether or not a given string pattern P appears in a string text T. ▫ Assume that length of P doesn’t exceed length of T ▫ Brute Force algorithm/First Pattern matching algorithm. 9
  • 10. 10
  • 11. ⬥ Let us take P= ‘GO’ and T= ‘ALGORITHM’ ⬥ So, R will be 2 and S will be 9 ⬥ Initially K=1, and MAX = 8 ⬥ K<=MAX, true -> step 3. ⬥ L= 1 to 2 repeat, ⬥ P[1]!=T[1], { that is G != A} ⬥ then K=2, ⬥ Now K<=MAX, true -> step 3 ⬥ L=1 to 2 repeat, ⬥ P[1]!=T[2], G!=L, then K=3 ⬥ Now K<=MAX, true step 3, ⬥ L=1 to 2 repeat, ⬥ P[1]=T[3], G=G TRUE, ⬥ L=2 ⬥ P[2]=T[3+2-1]= P[2]=T[4] ie. O=O ⬥ Index=3 and Exit. ⬥ Now we’ve Index of P in T at location 3 11
  • 12. Exercises You have the string text T=‘AROUND THE GLOBE’ 1. Find index of pattern ‘THE’ in T 2. Find index of pattern ‘HER’ in T 12