By Team Escalera
on 31 Oct 2017 03:15 PM
  • learn C#
0 comments

Lets Create a String and name it ‘x’

string x = “good text”;
Console.WriteLine(x.Length);

// x.Length will return the length of String, it will count spaces  as well.
//Outputs 9

Console.WriteLine(a.IndexOf(‘t’));

//It will return the position of ‘t’
//Outputs 5

x= x.Insert(0, “This is “);
Console.WriteLine(x);

//It will isert “This is” at position 0(zero) of the string
//Outputs “This is good text”

x= x.Replace(“This is”, “I am”);
Console.WriteLine(a);

// This code will replace the words “This is” with “I am”
//Outputs “I am good text”

if(x.Contains(“good”))
Console.WriteLine(“found”);

//This condition checks for a specific word in the string
//Outputs “found”

x= x.Remove(4);
Console.WriteLine(x);

// This will remove all the characters in the string after the specified position
//Outputs “I am”

x= x.Substring(2);
Console.WriteLine(a);

// Code will look for all the words after position 2 and print them, if a limit is specified it will print the characters upto that limit
//Outputs “am”

 

Another Example –

text = “This is a car. It is red”

text = text.IndexOf(“.”)+1);

//The code will look for position of x and add one position and print the statement upto that position.

Comments (0)

Leave A Comment