Skip to content

Instantly share code, notes, and snippets.

@nk4dev
Created June 19, 2023 01:14
Show Gist options
  • Save nk4dev/e5b1db20f3e934975e8cd32a6a52c600 to your computer and use it in GitHub Desktop.
Save nk4dev/e5b1db20f3e934975e8cd32a6a52c600 to your computer and use it in GitHub Desktop.
index and substring
public class StrUtil {
public static void main(String[] args) {
// 文字列編集
String str = "aaa/aaaaaaa___________a";
// lastIndexOf -> 一致する複数の文字列の最後のやつを返す
// endStr.length()
String endStr = "/";
int endIndex = str.lastIndexOf(endStr) + endStr.length();
int x = endStr.length();
System.out.println(x);
// Substring
// 参考 -> https://www.javadrive.jp/start/string/index7.html
// 文字列切り出し
String result = str.substring(endIndex);
String work = result.replace("_", "");
//String work = str.substring(0, str.indexOf("_"));
//String work = str.substring(0,3);
System.out.println(endIndex);
System.out.println(work);
}
}
@nk4dev
Copy link
Author

nk4dev commented Jun 19, 2023

change public

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment