서브쿼리 / 쇼핑몰 게시판(파일 첨부 기능)
- 쇼핑몰 홈페이지에서 상품과 첨부파일 등록 기능 실행하고자 함.
- public String substring(int startIndex)
: startIndex부터 끝까지의 문자열을 리턴
- public String substring(int startIndex, int endIndex)
: startIndex(포함)부터 endIndex(불포함)까지의 문자열을 리턴
[참고] https://hianna.tistory.com/534 [어제 오늘 내일:티스토리]예제) String file1 = "abc.jpg"; -> 해당 첨부파일의 확장자명을 불러오고자 함 System.out.println(file1.substring(1, 5)); ➡️ file1의 문자열 중 2번째부터 4번째까지의 문자열을 잘라냄(*5번째는 불포함) ➡️ 출력 결과: bc.j
- indexOf(String) : 인자로 전달된 String의 index를 리턴(원하는 String을 찾지 못하면 -1을 리턴)
예제) String test = "Hello World"; test.indexOf("World") ➡️ 6
- indexOf(String, int) : 처음 몇글자를 건너띄고 특정 문자열 찾기
예제) String test = "Hello World"; System.out.println(test.indexOf("World",5)); ➡️ 6 ➡️ 변수 test에서 5번 index부터 "World"를 찾고 그 index를 리턴
- indexOf(int) : int 타입으로 전달된 값을 문자열에서 찾고 index를 리턴
예제) String test = "Hello World"; System.out.println(test.indexOf('o')); ➡️ 4
- indexOf(int, int) : 첫번째 int 타입 인자는 찾고자 하는 값, 두번째 int 는 탐색을 시작할 index를 의미.
예제) String test = "Hello World"; System.out.println(test.indexOf('o', 5)); ➡️ 7
- lastIndexOf(String) : indexOf는 문자열의 0번 index부터 특정 문자열을 탐색 / lastIndexOf는 반대방향으로 문자열을 찾고 싶을 때 사용.
예제) String test = "Hello World"; System.out.println(test.lastIndexOf("World")); ➡️ 6
- lastIndexOf(String, int) : 예 ) String test = "Hello World";
test.indexOf("Hello", 5) 는 변수 test에서 5번 index에서 뒤쪽 방향으로 "Hello"를 찾고 그 첫번째 index인 0을 리턴예제) String test = "Hello World"; System.out.println(test.lastIndexOf("World",5)); ➡️ -1
- lastIndexOf(int) : 반대 방향으로 아스키 코드를 찾을 때 사용
예제) String test = "Hello World"; System.out.println(test.lastIndexOf('o')); ➡️ 7
- lastIndextOf(int, int) : 첫번째 int 타입 인자는 찾고자 하는 아스키 값이고, 두번째 int 는 탐색을 시작할 index를 의미
예제) String test = "Hello World"; System.out.println(test.lastIndexOf('o',5)); ➡️ 4
- 원본 파일의 확장자만 추출
- 업로드되는 파일에서 확장자를 포함한 파일의 이름을 반환
String secondOriginFileName = img2.getOriginalFilename(); String extension = secondOriginFileName.substring(secondOriginFileName.lastIndexOf("."));