#TIL #elixirlang 변수를 출력할 때, 큰따옴표로 감싸고 싶다면
2019-01-08iex> answer = “yes" "yes" iex> "the answer is #{answer}" "the answer is yes"
string interpolation을 사용해서 문자열을 만들 때, 변수값을 넣을 수 있다.
변수에서 가져온 값이란 걸 강조하고 싶다. 어떻게?
iex> "the answer is \"#{answer}\"" "the answer is \"yes\”"
\
escape 문자를 사용해야 한다. 강조는 되지만 번거롭다. 좀 더 편한 괄호를 사용하고 말지.
iex> "the answer is #{inspect answer}" "the answer is \"yes\”"
inspect/2 함수를 사용하면 큰따옴표로 쉽게 감쌀 수 있다.
- category:
- til 173
- tags:
- elixirlang 34
@ohyecloudy
, ohyecloudy@gmail.com