반응형
Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Tags
- c#
- dataframe
- GIT
- matplotlib
- Java
- math
- Python
- Redshift
- numpy
- Apache
- gas
- django
- Excel
- PostgreSQL
- string
- array
- google apps script
- Kotlin
- Google Spreadsheet
- 파이썬
- PySpark
- PANDAS
- SQL
- Presto
- list
- hive
- Tkinter
- Google Excel
- Github
Archives
- Today
- Total
달나라 노트
Kotlin - format (문자열 삽입하기) 본문
728x90
반응형
Kotlin에도 Python의 {}.format과 비슷한 함수가 있습니다.
fun main() {
var test_text = "Test string %s" // 1
var inserted_text = "This is inserted" // 2
var final_text = test_text.format(inserted_text) // 3
println(test_text) // 4
println(final_text) // 5
}
-- Result
Test string %s
Test string This is inserted
위 코드를 봅시다.
1. test_text 변수를 만든 후 'Test string %s'라는 내용을 할당해줍니다.
%s는 다른 문자가 format method에 삽입될 위치를 의미합니다.
2. 삽입될 string을 담은 변수를 선언해줍니다.
3. format method를 이용해서 test_text의 %s 부분에 inserted_text를 삽입합니다.
4. %s는 print하면 그냥 %s라는 텍스트가 그대로 나오지만
5. 이것처럼 format method를 이용해서 어떤 다른 텍스트가 삽입된 문자열을 print해보면 제대로 삽입된 것을 알 수 있습니다.
728x90
반응형
'Kotlin' 카테고리의 다른 글
| Kotlin - take (collecion에서 원하는 개수의 요소들만 얻기) (0) | 2021.04.13 |
|---|---|
| Kotlin - shuffled (collecion에 있는 요소들을 랜덤하게 재배열하기) (0) | 2021.04.13 |
| Kotlin - lateinit (initialize 미루기) (0) | 2021.03.19 |
| Kotlin - super() (parent class의 method 그대로 쓰기) (0) | 2021.03.19 |
| Kotlin - toString(), toInt(), toDouble(), toIntOrNull(), toDoubleOrNull() (Datatype의 변경) (0) | 2021.03.18 |
Comments