Menu
Coddy logo textTech

여러 줄 문자열

Coddy Dart 여정의 기초 섹션에 포함된 레슨 — 94개 중 39번째.

여러 줄 문자열은 Dart에서 연결 연산자나 이스케이프 문자를 사용할 필요 없이 여러 줄에 걸친 문자열을 만들 수 있게 합니다.

삼중 따옴표를 사용하여 여러 줄 문자열을 생성하세요:

String poem = '''
Roses are red,
Violets are blue,
Dart is awesome,
And so are you!
''';

다중 줄 문자열을 출력하세요:

print(poem);

위 코드를 실행하면 출력 결과는 다음과 같습니다:

Roses are red,
Violets are blue,
Dart is awesome,
And so are you!
challenge icon

챌린지

쉬움

Dart에서 멀티라인 문자열을 사용하여 형식화된 이벤트 초대장을 생성하는 createEventInvitation이라는 함수를 만드세요.

이 함수는 다섯 개의 매개변수를 가져야 합니다:

  1. String eventName
  2. String date
  3. String time
  4. String location
  5. String? dresscode (nullable - 제공되지 않을 수 있음)

이 함수는 다음 형식의 형식화된 멀티라인 문자열 초대장을 반환해야 합니다:

YOU ARE INVITED!
====================
Event: [eventName]
Date: [date]
Time: [time]
Location: [location]
Dress Code: [dresscode or 'Casual attire' if dresscode is null]
====================
We hope to see you there!

이 형식화된 출력을 생성하기 위해 멀티라인 문자열(삼중 따옴표)과 문자열 보간을 사용하세요. 위에 표시된 정확한 형식을 유지하세요. 등호 선과 하단 메시지를 포함하여.

치트 시트

삼중 따옴표를 사용하여 여러 줄 문자열 생성:

String poem = '''
Roses are red,
Violets are blue,
Dart is awesome,
And so are you!
''';

여러 줄 문자열 출력:

print(poem);

여러 줄 문자열 내에서 문자열 보간 사용:

String message = '''
Event: $eventName
Date: $date
Location: $location
''';

직접 해보기

import 'dart:io';
import 'dart:convert';

// 서식 지정된 이벤트 초대장을 생성하는 함수
String createEventInvitation(String eventName, String date, String time, String location, String? dresscode) {
  // 다중 줄 문자열 초대장을 생성하기 위해 여기에 코드를 작성하세요
  // 다중 줄 문자열에는 삼중 따옴표 (''')를 사용하세요 기억하세요
  // 매개변수를 포함하기 위해 문자열 보간($variable)을 사용하세요
  // dresscode가 null인 경우 'Casual attire'를 대신 사용하세요
}

void main() {
  // 입력을 JSON으로 읽기
  String inputJson = stdin.readLineSync()!;
  Map<String, dynamic> eventData = jsonDecode(inputJson);
  
  // 입력에서 값 추출
  String eventName = eventData['eventName'];
  String date = eventData['date'];
  String time = eventData['time'];
  String location = eventData['location'];
  String? dresscode = eventData['dresscode']; // 이것은 null일 수 있습니다
  
  // 함수를 호출하고 결과를 출력하세요
  String invitation = createEventInvitation(eventName, date, time, location, dresscode);
  print(invitation);
}
quiz icon실력 점검

이 레슨에는 짧은 퀴즈가 포함되어 있습니다. 레슨을 시작해 문제를 풀고 진행 상황을 기록하세요.

기초의 모든 레슨