수색…


연결 및 보간법

더하기 ( + ) 연산자를 사용하여 문자열을 연결할 수 있습니다.

'Dart ' + 'is ' + 'fun!'; // 'Dart is fun!'

연결을 위해 인접한 문자열 리터럴을 사용할 수도 있습니다.

'Dart ' 'is ' 'fun!';    // 'Dart is fun!'

${} 를 사용하여 문자열 내의 Dart 표현식의 값을 보간 할 수 있습니다. 식별자를 평가할 때는 중괄호를 생략 할 수 있습니다.

var text = 'dartlang';
'$text has ${text.length} letters'; // 'dartlang has 8 letters'

유효한 문자열

문자열은 단일 또는 다중 행일 수 있습니다. 단일 줄 문자열은 작은 따옴표 또는 큰 따옴표를 사용하여 작성되며, 여러 줄은 삼중 따옴표를 사용하여 작성됩니다. 유효한 다트 문자열은 모두 다음과 같습니다.

'Single quotes';
"Double quotes";
'Double quotes in "single" quotes';
"Single quotes in 'double' quotes";

'''A
multiline
string''';

"""
Another
multiline
string""";

부품에서 건물 만들기

프로그래밍 방식으로 String을 생성하는 것은 StringBuffer를 사용하는 것이 가장 좋습니다. StringBuffer는 toString() 이 호출 될 때까지 새로운 String 객체를 생성하지 않습니다.

var sb = new StringBuffer();

sb.write("Use a StringBuffer");
sb.writeAll(["for ", "efficient ", "string ", "creation "]);
sb.write("if you are ")
sb.write("building lots of strings");

// or you can use method cascades:

sb
  ..write("Use a StringBuffer")
  ..writeAll(["for ", "efficient ", "string ", "creation "])
  ..write("if you are ")
  ..write("building lots of strings");

var fullString = sb.toString();

print(fullString); 
// Use a StringBufferfor efficient string creation if you are building lots of strings

sb.clear(); // all gone!


Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow