CopyPastehas never been so tasty!

Remove and Insert string in C#

by anonymous

  • 0
  • 0
  • 0
128 views

Remove and Insert string in C#

String.Join MethodString.Join method is used to join more than one string into one. It takes a string array and used a separator string which is to be placed in between every element of the string array.Syntax 

String.Join(".", Strings[]);

 String.Insert methodBy using String.Insert method, we can place a new string at the specified index position.Syntax

String.Insert(8, "abc ");

 String.Remove method String.Remove method removes the string at the specified index position continuing through the last index position to be removed.SyntaxString[].Remove(8, 5);

  The following code illustrates the use of String.Join, String.Insert and String.Remove method to join, insert and remove string from the string array. In this code we use a string array, string.Join method places a “.” between all substrings. String.Insert method places the word “good ”at the desired position in the given string array and String.Remove method removes the desired substring from the given indexes which are classifying its first occurrence position and last occurrence position.Code

 

class Program

    { 

 static void Main(string[] args)

        {

string[] myStrings = { "He", "is", "a",  "player" };

stringmyString = String.Join(".", myStrings);

 

string myString1 = myString.Insert(8, "good. ");

Console.WriteLine("New string added at desired position = " + myString1);

string myString2 = myString1.Remove(8, 5);

Console.WriteLine("New added string removed from desired position = " + myString2);

Console.ReadLine();

        }

     }

Add A Comment: