yose yose - 3 months ago 9
C# Question

C# - how to showing the selected character?

how to showing the selected character ?

before : string comPort = COM17


after : string comPort = COM1


i am really new in c#, thanks for your help.

Answer

You can use a plenty of options for this like the following:

Console.WriteLine("Result using SubString    : {0}", inputString.Substring(0,inputString.Length-1));
Console.WriteLine("Result using Take N Join  : {0}", String.Join("",inputString.Take(inputString.Length-1)));
Console.WriteLine("Result using Split N Join : {0}", String.Join("",inputString.Take(inputString.Length-1)));
Console.WriteLine("Result using Remove       : {0}", inputString.Remove(inputString.Length-1));     
Console.WriteLine("Result using Trim         : {0}", inputString.TrimEnd('7'));

See this Example

Comments