programing

String에서 곱슬곱슬한 대괄호 '{'를 이스케이프합니다.포맷

batch 2023. 4. 16. 14:44
반응형

String에서 곱슬곱슬한 대괄호 '{'를 이스케이프합니다.포맷

String을 사용할 때 리터럴컬괄호 문자를 표시하려면 어떻게 해야 합니까?포맷 방법?

예를 들어:

sb.AppendLine(String.Format("public {0} {1} { get; private set; }", 
prop.Type, prop.Name));

출력은 다음과 같습니다.

public Int32 MyProperty { get; private set; }

이중괄호 사용{{또는}}따라서 코드는 다음과 같습니다.

sb.AppendLine(String.Format("public {0} {1} {{ get; private set; }}", 
prop.Type, prop.Name));

// For prop.Type of "Foo" and prop.Name of "Bar", the result would be:
// public Foo Bar { get; private set; }

언급URL : https://stackoverflow.com/questions/3773857/escape-curly-brace-in-string-format

반응형