Unity3D

string.Format 메소드 for C# Unity3D

DragonTory 2020. 5. 26. 12:31
반응형

 

String.Format 메서드

 

디버그 할 때나 텍스트에 값을 넣을 때 + 말고

예전 c++  작업 할 때 처럼 포맷을 지정 해서 문자열을 만들면 편할 때가 있다. 

이 때 string.Format 메소드를 사용 하면 된다. 

 

int value = 10;

string text = "Value";

string result = string.Format("Example : {0} = {1}", text , value );

혹은 

Debug.Log( string.Format("Example : {0} = {1}", text , value ) );

 

형식 지정 :

string s = String.Format("It is now {0:d} at {0:t}", DateTime.Now);

자리수 지정 (  마이너스(-)는 왼쪽 정렬 ) :

String.Format("{0,-12}{1,8:yyyy}{2,12:N0}{3,8:yyyy}{4,12:N0}{5,14:P1}" , 생략.

 

String.Format 메서드 - Link

https://docs.microsoft.com/ko-kr/dotnet/api/system.string.format?view=netcore-3.1

 

String.Format 메서드 (System)

지정된 형식에 따라 개체의 값을 문자열로 변환하여 다른 문자열에 삽입 합니다.Converts the value of objects to strings based on the formats specified and inserts them into another string. String.Format 메서드를 처음 사��

docs.microsoft.com

 

반응형