-
[Ruby] array/string slicingcoding for food 2022. 7. 26. 13:03
arr = ["a", "b", "c", "d", "e"] print arr[1..3] => ["b", "c", "d"] # 기준을 잡은 인덱스 만큼 포괄적으로 묶음 (inclusive) print arr[1...3] => ["b", "c"] # 마지막 인덱스를 제외하고 묶음 (excluding the ele at endIdx) ---------------------------------------- str = "bootcamp" print str[3..-1] => tcamp print str[3..-2] => tcam print str[-2] => m # 데이터의 마지막 index는 -1로 약속한다. 맨 마지막이라 숫자 세기가 귀찮고.. index의 시작이 0 이기 때문에