[c#] 문자열 중간에 특정문자 삽입하기 00001111 -> 0000-1111 > C#/.Net/Blazor/IIS

본문 바로가기
사이트 내 전체검색

C#/.Net/Blazor/IIS

[c#] 문자열 중간에 특정문자 삽입하기 00001111 -> 0000-1111

페이지 정보

작성자 sbLAB 댓글 0건 조회 8,841회 작성일 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 

댓글목록

등록된 댓글이 없습니다.

회원로그인

접속자집계

오늘
299
어제
433
최대
1,279
전체
218,967

그누보드5
Copyright © sebom.com All rights reserved.