개발블로그
[유니티 에러]FormatException : Index (zero based) must be greater tna or equal to zero and less than the size of the argument list. 본문
오류 해결
[유니티 에러]FormatException : Index (zero based) must be greater tna or equal to zero and less than the size of the argument list.
dvmoo 2022. 1. 10. 12:55
★☆☆☆☆
string.Format("{1}", text);
위와 같이 인덱스번호가 안맞을 때 생기는 에러 이다.
string.Format("{0}, {1}", text_1, text_2);
번호를 순서대로 적어주면 해결 가능하다.
string text_1 = "A";
string text_2 = "B";
// 문자열 보간법 사용 X
string str_1 = string.Format("{0}, {1}", text_1, text_2)
Debug.Log(str_1); // A B
// 문자열 보간법 사용 O
string str_2 = string.Format($"{text_1} {text_2}");
Debug.Log(str_2); // A B
개인적으로 문자열 보간법(string interpolation)을 자주 사용하는 편인데, $"{}" 형태로 문자열을 묶으면 편리하다.
가독성이 좋아져서 코드가 조금 더 잘 읽히는 것 같다.