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

본문 바로가기

사이트 내 전체검색

C#/.Net/Blazor/IIS

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

작성일 19-05-06 18:18

페이지 정보

작성자sbLAB 조회 8,840회 댓글 0건

본문

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 

댓글목록

등록된 댓글이 없습니다.

Copyright © 소유하신 도메인. All rights reserved.
PC 버전으로 보기