Q:

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

0

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

Sample Output:

Input a string : w3resource                                            
wrsuc

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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);
    }
  }

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now