How To Insert One String Into Another Using Insert() In C#
Maybe your like
Overview
In C#, the Insert() method takes a string and inserts it into another string. Insert() accepts the index position to start the insertion from, inserts the second string at the index position of the first string, and then returns the modified string.
Syntax
public string Insert(int32 first, String second)Parameters
- first: The index position to start the insertion at.
- second: The string we want to insert into another.
Return value
The Insert method returns a modified string.
Code example
The example below demonstrates the use of the Insert method to insert a string into another string.
// create our classclass StringInserter{ // main method static void Main() { // create strings to insert to string str1 = "Hlo"; string str2 = "ld"; // insert strings to the string above string modStr1 = str1.Insert(1, "el"); string modStr2 = str2.Insert(0, "wor"); // print returned modified strings System.Console.WriteLine(modStr1); System.Console.WriteLine(modStr2); }}RunIn the code above, we insert "el" to "Hlo", starting from the second position, to form "Hello". We also insert "wor" to "ld", thus modifying it to "world". This is the use of the Insert() method in C#.
Relevant Answers
Explore Courses
Free Resources
License: Creative Commons-Attribution-ShareAlike 4.0 (CC-BY-SA 4.0)Tag » Add Character To String C Sharp
-
C# Adding A Character In A String - Stack Overflow
-
Add Character To String C# Code Example - Code Grepper
-
String.Insert(Int32, String) Method (System) - Microsoft Docs
-
Append A Char To End Of A String In C# | Techie Delight
-
C# - How To Append A Char To A String - 1400+ .NET C# Examples
-
C# Add Strings - ZetCode
-
6 Effective Ways To Concatenate Strings In C# - C# Corner
-
How To Append A Character To A String In C - GeeksforGeeks
-
C# Strings - TutorialsTeacher
-
How Do I Add A Char To A String? - Unity Forum
-
C# - Add A Substring Before The First Occurrence Of A String
-
2.9. Inserting Text Into A String - C# Cookbook [Book] - O'Reilly
-
C# String Append (Add Strings) - Dot Net Perls
-
C# Strings - W3Schools