Instructions

링크

Given a string, you have to return a string in which each character (case-sensitive) is repeated once.

DoubleChar("String") == "SSttrriinngg"

DoubleChar("Hello World") == "HHeelllloo WWoorrlldd"

DoubleChar("1234!_ ") == "11223344!!__ "

My Solution

using System;
using System.Text;

public class Kata
{
  public static string DoubleChar(string s)
  {
    // your code here
    StringBuilder doubleStr = new StringBuilder();
    for (int i = 0; i < s.Length; i++)
    {
      doubleStr.Append(s[i]);
      doubleStr.Append(s[i]);
    }
    return doubleStr.ToString();
  }
}
  • 각 문자 2번씩 반복 하기.

Best Practices

using System;
using System.Linq;

public class Kata
{
  public static string DoubleChar(string s)
  {
    return string.Join("", s.Select(x => "" + x + x));
  }
}
  • Linq 사용.