국비교육(아이티센 입사교육)/Java
[Java] lastIndexOf 와 substring 문자열 자르기
영보로그
2021. 9. 27. 12:26
반응형
lastIndexOf 와 substring
lastIndexOf(String str)
Returns the index within this string of the last occurrence of the specified substring.
substring(int beginIndex)
Returns a string that is a substring of this string.
// substring(시작위치) 결과값 = ;
substring(int beginIndex, int endIndex)
Returns a string that is a substring of this string.
// substring(시작위치, 끝위치) 결과값 = ;
코드
package 변수와자료형;
// substring과 lastIndex 활용하여 문자열 자르기
public class URLPath2 {
public static void main(String[] args) {
String url = "http://locallhost:8080/Model2_Board/login.do";
int lastPosition = url.lastIndexOf("/");
System.out.println(lastPosition);
String filePath = url.substring(lastPosition);
System.out.println(filePath);
}
}
https://docs.oracle.com/javase/8/docs/api/
Java Platform SE 8
docs.oracle.com
반응형