mirror of
https://github.com/markjprice/cs11dotnet7.git
synced 2026-04-06 14:53:47 +00:00
Initial commit
This commit is contained in:
parent
c0d4d11b54
commit
0e89590d92
46 changed files with 1741 additions and 0 deletions
45
vscode/Chapter08/WorkingWithText/Program.cs
Normal file
45
vscode/Chapter08/WorkingWithText/Program.cs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
string city = "London";
|
||||
WriteLine($"{city} is {city.Length} characters long.");
|
||||
|
||||
WriteLine($"First char is {city[0]} and third is {city[2]}.");
|
||||
|
||||
string cities = "Paris,Tehran,Chennai,Sydney,New York,Medellín";
|
||||
|
||||
string[] citiesArray = cities.Split(',');
|
||||
|
||||
WriteLine($"There are {citiesArray.Length} items in the array.");
|
||||
|
||||
foreach (string item in citiesArray)
|
||||
{
|
||||
WriteLine(item);
|
||||
}
|
||||
|
||||
string fullName = "Alan Jones";
|
||||
|
||||
int indexOfTheSpace = fullName.IndexOf(' ');
|
||||
|
||||
string firstName = fullName.Substring(
|
||||
startIndex: 0, length: indexOfTheSpace);
|
||||
|
||||
string lastName = fullName.Substring(
|
||||
startIndex: indexOfTheSpace + 1);
|
||||
|
||||
WriteLine($"Original: {fullName}");
|
||||
WriteLine($"Swapped: {lastName}, {firstName}");
|
||||
|
||||
string company = "Microsoft";
|
||||
bool startsWithM = company.StartsWith("M");
|
||||
bool containsN = company.Contains("N");
|
||||
WriteLine($"Text: {company}");
|
||||
WriteLine($"Starts with M: {startsWithM}, contains an N: {containsN}");
|
||||
|
||||
string recombined = string.Join(" => ", citiesArray);
|
||||
WriteLine(recombined);
|
||||
|
||||
string fruit = "Apples";
|
||||
decimal price = 0.39M;
|
||||
DateTime when = DateTime.Today;
|
||||
|
||||
WriteLine($"Interpolated: {fruit} cost {price:C} on {when:dddd}.");
|
||||
WriteLine(string.Format("string.Format: {0} cost {1:C} on {2:dddd}.",
|
||||
arg0: fruit, arg1: price, arg2: when));
|
||||
Loading…
Add table
Add a link
Reference in a new issue