Last active
February 15, 2019 23:32
-
-
Save donchan922/f71557f8495f9f57c9bd4371c9eda4a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public static void main(String[] args) { | |
// 文字列全体 | |
String str = "<head><title>abc</title></head>"; | |
// 切り出したい文字列(開始) | |
String beginStr = "<title>"; | |
// 切り出したい文字列(開始)の開始位置 | |
int beginIndex = str.indexOf(beginStr); // 6 | |
// 切り出したい文字列(終了) | |
String endStr = "</title>"; | |
// 切り出したい文字列(終了)の終了位置 | |
int endIndex = str.indexOf(endStr) + endStr.length(); // 24 | |
// 文字列を切り出す | |
String strSubstring = str.substring(beginIndex, endIndex); | |
System.out.println(strSubstring); // <title>abc</title> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment