![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Insert() Method in C#
The Insert() method in C# is used to return a new string in which a specified string is inserted at a specified index position in this instance.
Syntax
The syntax is as follows −
public string Insert (int begnIndex, string val);
Above, the parameter begnIndex is the zero-based index position of the insertion, whereas val is the string to insert.
Example
Let us now see an example −
using System; public class Demo{ public static void Main(){ String str = "JohnWick"; Console.WriteLine("Initial string = "+str); String res = str.Insert(5, " "); Console.WriteLine("Updated = "+res); } }
Output
This will produce the following output −
Initial string = JohnWick Updated = JohnW ick
Example
Let us now see another example
using System; public class Demo{ public static void Main(){ String str = "WelcomeJacob"; Console.WriteLine("Initial string = "+str); String res = str.Insert(7, " here, "); Console.WriteLine("Updated = "+res); } }
Output
This will produce the following output −
Initial string = WelcomeJacob Updated = Welcome here, Jacob
Advertisements