SlideShare a Scribd company logo
C# FOR BEGINNERS
LESSON 5
MICHEAL OGUNDERO
CONTACT :
EMAIL – OGUNDEROAYODEJI@GMAIL.COM
Escape Sequences, Substitution Markers and
SubstitutionValues.
ESCAPE SEQUENCES…
• C# string literals can include various unprintable control characters,
such as tab, newline, or carriage-return.
• You cannot directly type these as a literal value instead C# escape
sequences must be used.
• An escape sequence is represented by a backslash (), followed by a
specific character that has special meaning to the compiler. For
example, “n” represents a newline in a double-quoted string.
ESCAPE SEQUENCES…
Escape Sequence Meaning
’ Output a Single quote.
” Output a double quote.
 Output a Backslash.
n Insert a newline.
r Insert a carriage-return.
t Insert a tab.
0 Insert a null character.
b Insert a backspace.
ESCAPE SEQUENCES…
• To print a string that contains a newline, the escape character “n” is used.
Class Program
{
public static void Main(string [] args)
{
string welcomeMessage = "HellonAvero";
Console.WriteLine(welcomeMessage);
}
}
OUTPUT:
Hello
Avero
It’s time to try out others from the table.
C#VERBATIM STRINGS @
• Trying to embed all those double backslashes when you need single
backslash is annoying and hard to read.
• To avoid this problem, most programmers use an alternate technique
called verbatim string literals.
• You prefix a string literal with an at-sign (@) to create a verbatim
string.
• Adding @ symbol before the string disables the support of escape
sequences and a string is interpreted as is.
C#VERBATIM STRINGS
Class Program
{
public static void Main(string [] args)
{
string welcomeMessage = @"HellonAvero";
Console.WriteLine(welcomeMessage);
}
}
OUTPUT:
HellonPirzada
C#VERBATIM STRINGS
• A verbatim identifier can also be used to split a statement across multiple lines
in the source code without the use of “n” escape character.
Class Program
{
public static void Main(string [] args)
{
string welcomeMessage = @"Hello
Avero";
Console.WriteLine(welcomeMessage);
}
}
ANOTHER ONE FOR THE CLASS!
• You can directly insert a double quote into a literal string just by doubling the
quotes (“”).This will interpret as a single quotation mark (“).
Class Program
{
public static void Main(string [] args)
{
string welcomeMessage = @"I am an "”Engineer"".";
Console.WriteLine(welcomeMessage);
}
}
OUTPUT:
I am an “Engineer”.
SUBSTITUTION MARKERS ANDVALUES…
• Substitution values are used to display the values of program
data and variables.
• A substitution marker marks the position in the format string
where a value should be substituted in the output string.
• It consists of an integer enclosed in a set of matching curly
braces.
• The integer is the numeric position of the substitution value to
be used.
SUBSTITUTION MARKERS ANDVALUES
• where parameter 0 is first (value ”Avero"), parameter 1 is second (
value ”Ire"), and parameter 2 is third (value ”Bisi").
Class Program
{
public static void Main(string [] args)
{
string first = ”Avero"; string second = ”Ire";
string third = ”Bisi";
Console.WriteLine("{0} {1}, {0} {1}, {2}.", first, second, third);
}
}
Avero Ire,Avero Ire, Bisi.
ANOTHER ONE FOR THE CLASS!
Class Program
{
public static void Main(string [] args)
{
int x = 2; int y = 4;
Console.WriteLine("{0} plus {1} = {2}; {0} times {1} = {3}.", x, y, x+y, x*y);
}
}
READING INPUT FROM USERS…
Class Program
{
public static void Main(string [] args)
{
Console.WriteLine ("What is your name?");
string name = Console.ReadLine ();
Console.WriteLine ("Hello, " + name + "!")
}
}
Notice the “+” sign instead of the usual substitution markers.
The
“Console.ReadLine”
takes user input
READING INPUT FROM USER
• Note the following features:
• Parameters can be any expression, and the expressions get evaluated before
printing.
• Parameters to be substituted can be of any type.
• The parameters are automatically converted to a string form
CLASSWORK
•Modify the addition program to take inputs from users
inputs this time around.
•Take the name of the user and store it in a username
variable
•Personalize the message that displays the result.
CLASSWORK
•What is the difference between
“Console.Write” and
“Console.WriteLine”?
CLASSWORK
•Write an application that displays the box below in
the console window
ASSIGNMENT
•Write an application that displays the shapes below in
the console window
REFERENCES
• Visual C# How to Program (6th Edition) (Deitel Series)
• Illustrated C# 2005 by Daniel Solis
• https://www.codebuns.com/csharp/escape-sequences/

More Related Content

What's hot

Cinfo
CinfoCinfo
Cinfo
teach4uin
 
CLASS VIII COMPUTERS FLOW CHART AND ALGORITHM
CLASS VIII COMPUTERS FLOW CHART AND ALGORITHMCLASS VIII COMPUTERS FLOW CHART AND ALGORITHM
CLASS VIII COMPUTERS FLOW CHART AND ALGORITHM
Rc Os
 
How c program execute in c program
How c program execute in c program How c program execute in c program
How c program execute in c program
Rumman Ansari
 
Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04hassaanciit
 
Activities on Operands
Activities on OperandsActivities on Operands
Activities on Operands
Nicole Ynne Estabillo
 
Function Pointer in C
Function Pointer in CFunction Pointer in C
Function Pointer in C
Lakshmi Sarvani Videla
 
parameter passing in c#
parameter passing in c#parameter passing in c#
parameter passing in c#
khush_boo31
 
Function
FunctionFunction
Function
mshoaib15
 
6nullables in c#
6nullables in c#6nullables in c#
6nullables in c#
Sireesh K
 
Exp 3-2 d422 (1)
Exp 3-2  d422 (1)Exp 3-2  d422 (1)
Exp 3-2 d422 (1)
Omkar Rane
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
Vraj Patel
 
OOPS With CSharp - Jinal Desai .NET
OOPS With CSharp - Jinal Desai .NETOOPS With CSharp - Jinal Desai .NET
OOPS With CSharp - Jinal Desai .NET
jinaldesailive
 
Types of function call
Types of function callTypes of function call
Types of function call
ArijitDhali
 
User Defined Functions in C Language
User Defined Functions   in  C LanguageUser Defined Functions   in  C Language
User Defined Functions in C Language
Infinity Tech Solutions
 
Compiler design lab programs
Compiler design lab programs Compiler design lab programs
Compiler design lab programs
Guru Janbheshver University, Hisar
 
Interface and abstraction
Interface and abstractionInterface and abstraction
Interface and abstractionRaghav Chhabra
 
[ITP - Lecture 12] Functions in C/C++
[ITP - Lecture 12] Functions in C/C++[ITP - Lecture 12] Functions in C/C++
[ITP - Lecture 12] Functions in C/C++
Muhammad Hammad Waseem
 
PL/SQL Part 3
PL/SQL Part 3PL/SQL Part 3
PL/SQL Part 3
Gurpreet singh
 
Pseudocode
PseudocodePseudocode
Pseudocode
Harsha Madushanka
 

What's hot (20)

Cinfo
CinfoCinfo
Cinfo
 
CLASS VIII COMPUTERS FLOW CHART AND ALGORITHM
CLASS VIII COMPUTERS FLOW CHART AND ALGORITHMCLASS VIII COMPUTERS FLOW CHART AND ALGORITHM
CLASS VIII COMPUTERS FLOW CHART AND ALGORITHM
 
Output
OutputOutput
Output
 
How c program execute in c program
How c program execute in c program How c program execute in c program
How c program execute in c program
 
Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04
 
Activities on Operands
Activities on OperandsActivities on Operands
Activities on Operands
 
Function Pointer in C
Function Pointer in CFunction Pointer in C
Function Pointer in C
 
parameter passing in c#
parameter passing in c#parameter passing in c#
parameter passing in c#
 
Function
FunctionFunction
Function
 
6nullables in c#
6nullables in c#6nullables in c#
6nullables in c#
 
Exp 3-2 d422 (1)
Exp 3-2  d422 (1)Exp 3-2  d422 (1)
Exp 3-2 d422 (1)
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
 
OOPS With CSharp - Jinal Desai .NET
OOPS With CSharp - Jinal Desai .NETOOPS With CSharp - Jinal Desai .NET
OOPS With CSharp - Jinal Desai .NET
 
Types of function call
Types of function callTypes of function call
Types of function call
 
User Defined Functions in C Language
User Defined Functions   in  C LanguageUser Defined Functions   in  C Language
User Defined Functions in C Language
 
Compiler design lab programs
Compiler design lab programs Compiler design lab programs
Compiler design lab programs
 
Interface and abstraction
Interface and abstractionInterface and abstraction
Interface and abstraction
 
[ITP - Lecture 12] Functions in C/C++
[ITP - Lecture 12] Functions in C/C++[ITP - Lecture 12] Functions in C/C++
[ITP - Lecture 12] Functions in C/C++
 
PL/SQL Part 3
PL/SQL Part 3PL/SQL Part 3
PL/SQL Part 3
 
Pseudocode
PseudocodePseudocode
Pseudocode
 

Similar to escape sequences and substitution markers

Visual c sharp
Visual c sharpVisual c sharp
Visual c sharp
Palm Palm Nguyễn
 
Lecture 3 getting_started_with__c_
Lecture 3 getting_started_with__c_Lecture 3 getting_started_with__c_
Lecture 3 getting_started_with__c_
eShikshak
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)
Chhom Karath
 
Chapter1.pptx
Chapter1.pptxChapter1.pptx
Chapter1.pptx
SREEVIDYAP10
 
Introduction to C#
Introduction to C#Introduction to C#
Introduction to C#
ANURAG SINGH
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
K Durga Prasad
 
C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)
Saifur Rahman
 
Synapseindia dot net development
Synapseindia dot net developmentSynapseindia dot net development
Synapseindia dot net development
Synapseindiappsdevelopment
 
c++-language-1208539706757125-9.pdf
c++-language-1208539706757125-9.pdfc++-language-1208539706757125-9.pdf
c++-language-1208539706757125-9.pdf
nisarmca
 
434090527-C-Cheat-Sheet. pdf C# program
434090527-C-Cheat-Sheet. pdf  C# program434090527-C-Cheat-Sheet. pdf  C# program
434090527-C-Cheat-Sheet. pdf C# program
MAHESHV559910
 
Ppt of c vs c#
Ppt of c vs c#Ppt of c vs c#
Ppt of c vs c#
shubhra chauhan
 
C programming language
C programming languageC programming language
C programming language
Mahmoud Eladawi
 

Similar to escape sequences and substitution markers (20)

Visual c sharp
Visual c sharpVisual c sharp
Visual c sharp
 
Basic Input and Output
Basic Input and OutputBasic Input and Output
Basic Input and Output
 
Lecture 3 getting_started_with__c_
Lecture 3 getting_started_with__c_Lecture 3 getting_started_with__c_
Lecture 3 getting_started_with__c_
 
First c program
First c programFirst c program
First c program
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)
 
Csharp_Chap06
Csharp_Chap06Csharp_Chap06
Csharp_Chap06
 
Chapter1.pptx
Chapter1.pptxChapter1.pptx
Chapter1.pptx
 
Csharp_mahesh
Csharp_maheshCsharp_mahesh
Csharp_mahesh
 
Introduction to C#
Introduction to C#Introduction to C#
Introduction to C#
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
 
C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)
 
Basics1
Basics1Basics1
Basics1
 
Synapseindia dot net development
Synapseindia dot net developmentSynapseindia dot net development
Synapseindia dot net development
 
c++-language-1208539706757125-9.pdf
c++-language-1208539706757125-9.pdfc++-language-1208539706757125-9.pdf
c++-language-1208539706757125-9.pdf
 
Basics of objective c
Basics of objective cBasics of objective c
Basics of objective c
 
C notes.pdf
C notes.pdfC notes.pdf
C notes.pdf
 
434090527-C-Cheat-Sheet. pdf C# program
434090527-C-Cheat-Sheet. pdf  C# program434090527-C-Cheat-Sheet. pdf  C# program
434090527-C-Cheat-Sheet. pdf C# program
 
Ppt of c vs c#
Ppt of c vs c#Ppt of c vs c#
Ppt of c vs c#
 
C programming language
C programming languageC programming language
C programming language
 

More from Micheal Ogundero

static methods
static methodsstatic methods
static methods
Micheal Ogundero
 
c# operators
c# operatorsc# operators
c# operators
Micheal Ogundero
 
datatypes_variables_constants
datatypes_variables_constantsdatatypes_variables_constants
datatypes_variables_constants
Micheal Ogundero
 
2 robot types_classifications
2 robot types_classifications2 robot types_classifications
2 robot types_classifications
Micheal Ogundero
 
History of robots
History of robotsHistory of robots
History of robots
Micheal Ogundero
 
c# keywords, identifiers and Naming Conventions
c# keywords, identifiers and Naming Conventionsc# keywords, identifiers and Naming Conventions
c# keywords, identifiers and Naming Conventions
Micheal Ogundero
 
Dictionary and sets-converted
Dictionary and sets-convertedDictionary and sets-converted
Dictionary and sets-converted
Micheal Ogundero
 
Basic Sorting algorithms csharp
Basic Sorting algorithms csharpBasic Sorting algorithms csharp
Basic Sorting algorithms csharp
Micheal Ogundero
 
Csharp_List
Csharp_ListCsharp_List
Csharp_List
Micheal Ogundero
 
c# Enumerations
c# Enumerationsc# Enumerations
c# Enumerations
Micheal Ogundero
 
csharp_Passing_parameters_by_value_and_reference
csharp_Passing_parameters_by_value_and_referencecsharp_Passing_parameters_by_value_and_reference
csharp_Passing_parameters_by_value_and_reference
Micheal Ogundero
 
C# Value Data Types and Reference Data Types
C# Value Data Types and Reference Data TypesC# Value Data Types and Reference Data Types
C# Value Data Types and Reference Data Types
Micheal Ogundero
 

More from Micheal Ogundero (12)

static methods
static methodsstatic methods
static methods
 
c# operators
c# operatorsc# operators
c# operators
 
datatypes_variables_constants
datatypes_variables_constantsdatatypes_variables_constants
datatypes_variables_constants
 
2 robot types_classifications
2 robot types_classifications2 robot types_classifications
2 robot types_classifications
 
History of robots
History of robotsHistory of robots
History of robots
 
c# keywords, identifiers and Naming Conventions
c# keywords, identifiers and Naming Conventionsc# keywords, identifiers and Naming Conventions
c# keywords, identifiers and Naming Conventions
 
Dictionary and sets-converted
Dictionary and sets-convertedDictionary and sets-converted
Dictionary and sets-converted
 
Basic Sorting algorithms csharp
Basic Sorting algorithms csharpBasic Sorting algorithms csharp
Basic Sorting algorithms csharp
 
Csharp_List
Csharp_ListCsharp_List
Csharp_List
 
c# Enumerations
c# Enumerationsc# Enumerations
c# Enumerations
 
csharp_Passing_parameters_by_value_and_reference
csharp_Passing_parameters_by_value_and_referencecsharp_Passing_parameters_by_value_and_reference
csharp_Passing_parameters_by_value_and_reference
 
C# Value Data Types and Reference Data Types
C# Value Data Types and Reference Data TypesC# Value Data Types and Reference Data Types
C# Value Data Types and Reference Data Types
 

Recently uploaded

Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 

Recently uploaded (20)

Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 

escape sequences and substitution markers

  • 1. C# FOR BEGINNERS LESSON 5 MICHEAL OGUNDERO CONTACT : EMAIL – OGUNDEROAYODEJI@GMAIL.COM Escape Sequences, Substitution Markers and SubstitutionValues.
  • 2. ESCAPE SEQUENCES… • C# string literals can include various unprintable control characters, such as tab, newline, or carriage-return. • You cannot directly type these as a literal value instead C# escape sequences must be used. • An escape sequence is represented by a backslash (), followed by a specific character that has special meaning to the compiler. For example, “n” represents a newline in a double-quoted string.
  • 3. ESCAPE SEQUENCES… Escape Sequence Meaning ’ Output a Single quote. ” Output a double quote. Output a Backslash. n Insert a newline. r Insert a carriage-return. t Insert a tab. 0 Insert a null character. b Insert a backspace.
  • 4. ESCAPE SEQUENCES… • To print a string that contains a newline, the escape character “n” is used. Class Program { public static void Main(string [] args) { string welcomeMessage = "HellonAvero"; Console.WriteLine(welcomeMessage); } } OUTPUT: Hello Avero It’s time to try out others from the table.
  • 5. C#VERBATIM STRINGS @ • Trying to embed all those double backslashes when you need single backslash is annoying and hard to read. • To avoid this problem, most programmers use an alternate technique called verbatim string literals. • You prefix a string literal with an at-sign (@) to create a verbatim string. • Adding @ symbol before the string disables the support of escape sequences and a string is interpreted as is.
  • 6. C#VERBATIM STRINGS Class Program { public static void Main(string [] args) { string welcomeMessage = @"HellonAvero"; Console.WriteLine(welcomeMessage); } } OUTPUT: HellonPirzada
  • 7. C#VERBATIM STRINGS • A verbatim identifier can also be used to split a statement across multiple lines in the source code without the use of “n” escape character. Class Program { public static void Main(string [] args) { string welcomeMessage = @"Hello Avero"; Console.WriteLine(welcomeMessage); } }
  • 8. ANOTHER ONE FOR THE CLASS! • You can directly insert a double quote into a literal string just by doubling the quotes (“”).This will interpret as a single quotation mark (“). Class Program { public static void Main(string [] args) { string welcomeMessage = @"I am an "”Engineer""."; Console.WriteLine(welcomeMessage); } } OUTPUT: I am an “Engineer”.
  • 9. SUBSTITUTION MARKERS ANDVALUES… • Substitution values are used to display the values of program data and variables. • A substitution marker marks the position in the format string where a value should be substituted in the output string. • It consists of an integer enclosed in a set of matching curly braces. • The integer is the numeric position of the substitution value to be used.
  • 10. SUBSTITUTION MARKERS ANDVALUES • where parameter 0 is first (value ”Avero"), parameter 1 is second ( value ”Ire"), and parameter 2 is third (value ”Bisi"). Class Program { public static void Main(string [] args) { string first = ”Avero"; string second = ”Ire"; string third = ”Bisi"; Console.WriteLine("{0} {1}, {0} {1}, {2}.", first, second, third); } } Avero Ire,Avero Ire, Bisi.
  • 11. ANOTHER ONE FOR THE CLASS! Class Program { public static void Main(string [] args) { int x = 2; int y = 4; Console.WriteLine("{0} plus {1} = {2}; {0} times {1} = {3}.", x, y, x+y, x*y); } }
  • 12. READING INPUT FROM USERS… Class Program { public static void Main(string [] args) { Console.WriteLine ("What is your name?"); string name = Console.ReadLine (); Console.WriteLine ("Hello, " + name + "!") } } Notice the “+” sign instead of the usual substitution markers. The “Console.ReadLine” takes user input
  • 13. READING INPUT FROM USER • Note the following features: • Parameters can be any expression, and the expressions get evaluated before printing. • Parameters to be substituted can be of any type. • The parameters are automatically converted to a string form
  • 14. CLASSWORK •Modify the addition program to take inputs from users inputs this time around. •Take the name of the user and store it in a username variable •Personalize the message that displays the result.
  • 15. CLASSWORK •What is the difference between “Console.Write” and “Console.WriteLine”?
  • 16. CLASSWORK •Write an application that displays the box below in the console window
  • 17. ASSIGNMENT •Write an application that displays the shapes below in the console window
  • 18. REFERENCES • Visual C# How to Program (6th Edition) (Deitel Series) • Illustrated C# 2005 by Daniel Solis • https://www.codebuns.com/csharp/escape-sequences/