Kotlin 문자열가공 문자열자르기 split, slicing

Kotlin 문자열가공 문자열자르기 split, slicing

// 문자열 가공 // 유저가 입력한 데이터를 가공하거나 // 서버에서 가져온 데이터를 알맞게 가공해서 쓰거나 fun main(){ // val testString : String = "동해물과 백두산이 마르고 닳도록" // println(testString) // // 문자열 자르기 // val newTestString = testString.split(" ") // println(newTestString) // println(newTestString::class.java.simpleName) // println(testString[0]) // println(newTestString[0]) // // 슬라이싱 하기 // println(testString.substring(0,2)) // //끝자리까지 가져오기 // println(testString.substring(0,testString.length)) // //문자열바꾸기 // val replaceName = testString.replace("백두산", "한라산") // println(replaceName) val emailList = ArrayList() emailList.add("[email protected]") emailList.add("[email protected]") emailList.add("[email protected]") // 첫번째 방법으로는 naver라는 텍스트가 포함되었는지 차직 // [email protected] 이러한 문제가있음 // 두번째 방법으로는 @뒤에 naver라고 텍스트가 있는지 찾기 val naverList = ArrayList() var count = 0 for (email in emailList){ if (email.split("@")[1].split(".")[0] == "naver"){ naverList.add(email) count ++ } } println(naverList) println(count) }

공유하기 글 요소 저작자표시

from http://yoo-young.tistory.com/83 by ccl(A) rewrite - 2021-12-21 13:01:44