2014-09-10 3 views
0

String.Format() 메서드에서이 오류가 발생하고 왜 모든 것이 나에게 좋을지 모르겠습니까?String.Format() - 입력 문자열의 형식이 올바르지 않음

string fontface = ""; 

foreach(...) 
{ 
    fontface = String.Format(@"{3} 
    @font-face { 
     font-family: '{0}'; 
     src: url('{0}.eot'); 
     src: url('{0}.eot') format('embedded-opentype'), 
       url('{0}.woff2') format('woff2'), 
       url('{0}.woff') format('woff'), 
       url('{0}.ttf') format('truetype'), 
       url('{0}.svg#{0}') format('svg'); 
     font-weight:{1}; 
     font-style:{2}; 
    }" 
    , family, weight, style, fontface); 
} 

답변

8

당신은 string.Format()'{' 또는 '}'이 자리의 일부 ('{0}' 등)이 같은

뭔가로 간주로 두 배로하여 "{", "}"을 탈출해야합니다

fontface = String.Format(@"{3} 
    @font-face {{ 
     font-family: '{0}'; 
     src: url('{0}.eot'); 
     src: url('{0}.eot') format('embedded-opentype'), 
       url('{0}.woff2') format('woff2'), 
       url('{0}.woff') format('woff'), 
       url('{0}.ttf') format('truetype'), 
       url('{0}.svg#{0}') format('svg'); 
     font-weight:{1}; 
     font-style:{2}; 
    }}" 
    , family, weight, style, fontface); 
1

당신의 두 가지 문제는 라인 @font-face {}" 있습니다. Format을 사용할 때 중괄호를 두 개 사용하여 이스케이프 처리해야합니다. 그냥 @font-face {{에 선 사람들을 변경하고 }}"

+0

@ZeeTee,'@ font-face' 다음에'{' – Hassan

+0

을 사용 중입니다. –

관련 문제