Usage of string type in C#

Usage of string type in C#

@csharp_1001_notes

string msg = "We Love C#!";

char fourth = msg[3];

string thisnthat = "this" + "that";   // "thisthat"

string sub = msg.Substring(3, 4);  // "Love"

string dash = msg.Replace(' ', '-');  // "We-Love-C#!"

 

// Split into space-delimited words: "We", "Love", "C#!"

string[] words = msg.Split(new char[]{' '});

string concat = msg + " Yes we do.";

bool foundLove = words[1].ToLower() == "love";

 

// Convert to lowercase, find substring

int findLove = msg.ToLower().IndexOf("love");

 

// Iterate

foreach (char c in msg)

Console.Write(string.Format("{0}-", c));

Report Page