Insert
ExamplesΒΆ
The general syntax for this method is:
stringName.Insert(index, "stringValue");
This method returns a new string where a specific string has been inserted at a specific index.
Example
1 2 3 | Console.WriteLine("HelloWorld!".Insert(5, " "));
Console.WriteLine("fake.emaillaunchcode.org".Insert(10, "@"));
Console.WriteLine("abde".Insert(2, "c"));
|
Output
Hello World!
[email protected]
abcde
Example
This method could be used to create something like a department specific username.
This example adds department identification to a username with Insert
.
string input = "userName";
string devDeptCode = input.Insert(0, "019-wd:");
Console.WriteLine(devDeptCode);
Output
019-wd:userName