Use of strings 2

  • pptx
  • 02.05.2020
Публикация на сайте для учителей

Публикация педагогических разработок

Бесплатное участие. Свидетельство автора сразу.
Мгновенные 10 документов в портфолио.

Иконка файла материала Use of strings 2.pptx

Don’t judge a man until you have walked a mile in his shoes.

English Proverb

What is the difference between declaration of string and its initialization ?

How to add one string another string?

// Declare without initializing.
string message1;
 
// Initialize to null.
string message2 = null;

Use of strings

LO: Use of procedures and functions for processing the strings

Evaluation Criteria:

Knowledge
• Know how to display Date in a string
• Know how to display Length of string

Understanding
• Describes how to search a word in sentence
• Describes how to work with Substring method of string

Application
• Write code for processing the strings using functions
• Write code for processing the strings using procedures

Vocabulary

Start index

Frequency

substring

split

pattern

contiguous

Useful expressions for dialogs :

Well, we should use the loop to find the frequency of a given word in … .
For example, substring is used to get first n characters substring from a string … .
Obviously, the Substring method makes it a lot easier to process strings in comparison with … .

Task 1 . Search a word (Handout 1)

Evaluation Criteria

Descriptors

Write code for processing the strings using functions

Types without errors the given functions code
Develops the code for main program that sends string and word to function
Outputs the frequency of word met in string

Describes how to search a word in sentence

students explain how to search a word in sentence

C# String.Substring method

In C#, a string is represented by the String class. The String.Substring method retrieves a substring from a string instance in C#. The method has the following two overloaded forms. 

Substring(Int32) - Retrieves a substring from the specified position to the end of the string.
Substring(Int32, Int32) - Retrieves a substring from this instance from the specified position for the specified length.

Get first n characters substring from a string in C# 

String characters are zero-indexed. Means, the position of the first characters in a string starts at 0th position. 

Let’s say, you want to get a substring of first 12 characters from a string.

We can use the Substring method and pass it starting index 0 and length of the substring 12 to get first 12 char substring from a string.

// A long string    

string bio = "Mahesh Chand is a founder of C# Corner. Mahesh is also an author, speaker, and software architect. Mahesh founded C# Corner in 2000.";    
    
// Get first 12 characters substring from a string  
  
string authorName = bio.Substring(0, 12);    
Console.WriteLine(authorName);

Task 2. (handout 2)

Substring method use case

Evaluation Criteria

Descriptors

Describes how to work with Substring method of string

explain the situation where substring is used
able to describe every line of code

Summary

Questions:

What is the substring?

When to use Substring method?