12
1.10 Strings academy.zariba.com 1

1.10 Strings academy.zariba.com 1. Lecture Content 1.What is a string? 2.Creating and Using strings 3.Manipulating Strings 4.Other String Operations 5.Building

Embed Size (px)

Citation preview

Page 1: 1.10 Strings academy.zariba.com 1. Lecture Content 1.What is a string? 2.Creating and Using strings 3.Manipulating Strings 4.Other String Operations 5.Building

1

1.10 Strings

academy.zariba.com

Page 2: 1.10 Strings academy.zariba.com 1. Lecture Content 1.What is a string? 2.Creating and Using strings 3.Manipulating Strings 4.Other String Operations 5.Building

2

Lecture Content

1. What is a string?2. Creating and Using strings3. Manipulating Strings4. Other String Operations5. Building strings6. Formatting Strings

Page 3: 1.10 Strings academy.zariba.com 1. Lecture Content 1.What is a string? 2.Creating and Using strings 3.Manipulating Strings 4.Other String Operations 5.Building

3

1. What is a string?

• Strings are sequences of characters.• Each character is a Unicode symbol.• String objects in C# are immutable(read-only).• Strings are like arrays of character. • Have a fixed length.• Characters can be accessed by index

Page 4: 1.10 Strings academy.zariba.com 1. Lecture Content 1.What is a string? 2.Creating and Using strings 3.Manipulating Strings 4.Other String Operations 5.Building

4

2. Creating and Using Strings

Page 5: 1.10 Strings academy.zariba.com 1. Lecture Content 1.What is a string? 2.Creating and Using strings 3.Manipulating Strings 4.Other String Operations 5.Building

5

3. Manipulating strings

Comparing, concatenating, searching, splitting etc.

Page 6: 1.10 Strings academy.zariba.com 1. Lecture Content 1.What is a string? 2.Creating and Using strings 3.Manipulating Strings 4.Other String Operations 5.Building

6

4. Other String Operations

Replacing and deleting substrings, changing character casing, trimming.

Page 7: 1.10 Strings academy.zariba.com 1. Lecture Content 1.What is a string? 2.Creating and Using strings 3.Manipulating Strings 4.Other String Operations 5.Building

7

5. Building Strings

Using the “+” operator to build strings is slow. This is why there is StringBuilder.

Page 8: 1.10 Strings academy.zariba.com 1. Lecture Content 1.What is a string? 2.Creating and Using strings 3.Manipulating Strings 4.Other String Operations 5.Building

8

6. Formatting String

Page 9: 1.10 Strings academy.zariba.com 1. Lecture Content 1.What is a string? 2.Creating and Using strings 3.Manipulating Strings 4.Other String Operations 5.Building

9

Homework

1. Write a program that reads a string, reverses it and prints the result at the console. Do NOT use any built in methods!

2. Write a program to check if in a given expression the brackets are put correctly. Correct:((x-y)/(10-z)). Incorrect: )(x*y)-1).

3. Write a program that finds how many times a substring is contained in a given text (perform case insensitive search).

4. Write a program that reads from the console a string of maximum 20 characters. If the length of the string is less than 20, the rest of the characters should be filled with '*'. Print the result string into the console.

5. Write a program that extracts from a given text all sentences containing given word.

Page 10: 1.10 Strings academy.zariba.com 1. Lecture Content 1.What is a string? 2.Creating and Using strings 3.Manipulating Strings 4.Other String Operations 5.Building

10

Homework

6. Write a program that reverses the words in given sentence.7. Write a program that extracts from a given text all sentences

containing given word.8. Write a program that extracts from a given text all

palindromes, e.g. “level", “stats", “radar".9. Write a program that reads a string from the console and prints

all different letters in the string along with information how many times each letter is found.

10. Write a program that reads a string from the console and lists all different words in the string along with information how many times each word is found.

11. Write a program that reads a string from the console and replaces all series of consecutive identical letters with a single one. Example: “zzzzzaaaarrrriiiiiiiibbbbbbbaaaaa" “zariba".

Page 11: 1.10 Strings academy.zariba.com 1. Lecture Content 1.What is a string? 2.Creating and Using strings 3.Manipulating Strings 4.Other String Operations 5.Building

11

References

Page 12: 1.10 Strings academy.zariba.com 1. Lecture Content 1.What is a string? 2.Creating and Using strings 3.Manipulating Strings 4.Other String Operations 5.Building

12

Zariba Academy

Questions