What is the difference between declaration of string and its initialization ?
How to add one string another string?
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
Useful expressions for dialogs :
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 |
Describes how to search a word in sentence | students explain how to search a word in sentence |
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 |
Материалы на данной страницы взяты из открытых источников либо размещены пользователем в соответствии с договором-офертой сайта. Вы можете сообщить о нарушении.