Skip to content

Instantly share code, notes, and snippets.

@donchan922
Last active February 15, 2019 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donchan922/f71557f8495f9f57c9bd4371c9eda4a8 to your computer and use it in GitHub Desktop.
Save donchan922/f71557f8495f9f57c9bd4371c9eda4a8 to your computer and use it in GitHub Desktop.
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