Remove spaces at both ends
Remove the spaces before and after a name. A space between two words stays in place. These examples use ordinary spaces.
String.Trim
Simple example
Trim the single letter.
Start' a '
Resulta
using System;
Console.WriteLine(" a ".Trim());
a
Advertisements
Everyday examples
Remove the extra spaces copied around a ticket number.
Start' B12 '
ResultB12
using System;
Console.WriteLine(" B12 ".Trim());
B12
Clean up the outside spaces on a shelf label.
Start' Red Apples '
ResultRed Apples
using System;
Console.WriteLine(" Red Apples ".Trim());
Red Apples
Clean up a name copied from a signup sheet.
Start' Ana '
ResultAna
using System;
Console.WriteLine(" Ana ".Trim());
Ana
Run the example
dotnet new console --output Lesson
cp Program.cs Lesson/Program.cs
dotnet run --project Lesson