How to create a new string from parts of a string in C#

2 Answers

0 votes
using System;
 
namespace ConsoleApplication1
{
    public delegate void mydelegate();

    class Program
    {
        static void Main(string[] args)
        {
            string s = "c# java c++";

            string part1 = s.Substring(0, 2);
            string part2 = s.Substring(3, 4);

            Console.WriteLine(part1);
            Console.WriteLine(part2);

            string allparts = part1 + " " + part2;
            Console.WriteLine(allparts);
        }
    }
}

/*
run:
     
c#
java
c# java
        
*/

 



answered Apr 24, 2017 by avibootz
0 votes
using System;
 
namespace ConsoleApplication1
{
    public delegate void mydelegate();

    class Program
    {
        static void Main(string[] args)
        {
            string s = "c# java c++";

            string allparts = s.Substring(0, 2) + " " + s.Substring(3, 4); 
            Console.WriteLine(allparts);
        }
    }
}

/*
run:
     
c# java
        
*/

 



answered Apr 24, 2017 by avibootz

Related questions

2 answers 278 views
2 answers 124 views
1 answer 120 views
1 answer 123 views
1 answer 116 views
116 views asked Apr 18, 2022 by avibootz
1 answer 147 views
...