2
JSoup을 사용하여 이미지를 긁어 내려고했는데 비틀 거리는 코드를 이해하지 못했습니다. 코드의src 속성 (url)에서 이미지 이름 추출
부 :
private static void getImages(String src) throws IOException {
String folder = null;
//Exctract the name of the image from the src attribute
int indexname = src.lastIndexOf("/");
if (indexname == src.length()) { // Don't understand this
src = src.substring(1, indexname);
}
indexname = src.lastIndexOf("/");
String name = src.substring(indexname, src.length());
// more code
}
나는 if
문을 이해하지 못하는 (SRC이 경우는 절대 URL로 정의된다). 더 구체적으로, indexname
은 언제 src의 길이와 같습니까?
'indexname == src.length()'이면'String'은 슬래시로 끝납니다. –
문자열 src가 백 슬래시로 끝나는 지 확인합니다. 이 경우 백 슬래시로 끝나는 경우에도 URL의 마지막 섹션을 가져 오는 방식으로이를 제거하고 다시 검사합니다. –
@ElliottFrisch no. 이 코드에는 버그가 있습니다. indexname은 src.length()와 결코 같지 않습니다. –