[c#] 문자열 중간에 특정문자 삽입하기 00001111 -> 0000-1111
페이지 정보
작성자 sbLAB 댓글 0건 조회 7,377회 작성일 19-05-06 18:18본문
using System;
public class Program
{
public static void Main()
{
Console.WriteLine(InsertCharAtDividedPosition("9876283309825079", 4, "-"));
}
public static string InsertCharAtDividedPosition(string str, int count, string character)
{
var i = 0;
while (++i * count + (i - 1) < str.Length)
{
str = str.Insert((i * count + (i - 1)), character);
}
return str;
}
}
[Result]
9876-2833-0982-5079
댓글목록
등록된 댓글이 없습니다.