본문 바로가기

유니티 프로그래밍/C# 프로그래밍

C# 문자열 서식 변경하는 방법

    class StringFormatBasic
    {
        static void Main(string[] args)
        {
            string fmt = "{0, -20}{1, -15}{2, 30}";

            WriteLine(fmt, "Publisher", "Author", "Title");
            WriteLine(fmt, "Marvel", "Stan Lee", "Irom Man");
            WriteLine(fmt, "Hanbit", "SangHyun Park", "This is C#");
            WriteLine(fmt, "Prentice Hall", "K&R", "The C Programming Language");

        }
    }

위와 같이 코딩을 하면 Publisher 라인은 전부 왼쪽 정렬, Auhor는 그 이후에 맞게 정렬  Title은 오른쪽 정렬된것처럼 정렬이 되서 서식이 변경된다.