How to use Substring to exclude the last N characters from a string in C#

2 Answers

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main()
        {
            string s = "c# java python php";

            string sub = s.Substring(0, s.Length - 4);

            Console.WriteLine(sub);
        }
    }
}


/*
run:
   
c# java python
 
*/

 



answered Aug 24, 2018 by avibootz
0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main()
        {
            string s = "c# java python php";

            s = s.Substring(0, s.Length -11);

            Console.WriteLine(s);
        }
    }
}


/*
run:
   
c# java
 
*/

 



answered Aug 24, 2018 by avibootz

Related questions

...