w3resource
C# Sharp Programming Exercises

C# Sharp Exercises: Create a new string of every other character from the first position of a given string

C# Sharp Basic: Exercise-44 with Solution

Write a C# program to create a new string of every other character (odd position) from the first position of a given string.

Pictorial Presentation:

>C# Sharp Exercises: Create a new string of every other character from the first position of a given string

Sample Solution:-

C# Sharp Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class Exercise44 {
static void Main(string[] args)
    {
            Console.Write("Input a string : ");
            string str = Console.ReadLine();
            var result = string.Empty;
            for (var i = 0; i < str.Length; i++)
              {
                if (i % 2 == 0) result += str[i];
              }
            Console.WriteLine(result);
    }
  }

Sample Output:

Input a string : w3resource                                            
wrsuc

Flowchart:

Flowchart: C# Sharp Exercises - Create a new string of every other character from the first position of a given string

C# Sharp Code Editor:

Improve this sample solution and post your code through Disqus

Previous: Write a C# program to check if a given string starts with "w" and immediately followed by two "ww".
Next: Write a C# program to count a specified number in a given array of integers.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming