Created
June 19, 2023 01:14
-
-
Save nk4dev/e5b1db20f3e934975e8cd32a6a52c600 to your computer and use it in GitHub Desktop.
index and substring
This file contains hidden or 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 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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
change public