有没有一个简单的方法 来得到一个字符串的倒数第二 限定的子字符串?
String original = "/1/6/P_55/T_140";
在此示例中, 产生的子字符串将是 "P_ 55/ T_140"
我想在此子字符串(/
)开头找到前斜线索引。
我知道 < code> string. lastIndexof () 两次打电话会有帮助。 但寻找一种通用的更清洁的方法。 可能对任何 N 来说 。
有没有一个简单的方法 来得到一个字符串的倒数第二 限定的子字符串?
String original = "/1/6/P_55/T_140";
在此示例中, 产生的子字符串将是 "P_ 55/ T_140"
我想在此子字符串(/
)开头找到前斜线索引。
我知道 < code> string. lastIndexof () 两次打电话会有帮助。 但寻找一种通用的更清洁的方法。 可能对任何 N 来说 。
但寻找一种通用的清洁方法。
拨打String.LastIndexof(int,int)
在循环中将会相当高效,
int pos = str.length();
for (int i = 0; i < n; i++) {
pos = str.lastIndexOf( / , pos - 1);
}
String out = str.substring(pos + 1);
这可以很容易地转换为辅助函数, 使用 str
, /
/ <
和 , 并返回
out
。
获取媒体文件所在的文件夹名称
/储存/模拟/0/WhatsApp/Media/ whatsApp 视频/VID-20170812-WA0000.mp4
使用以下代码
String folderName = filePath.substring(filePath.lastIndexOf( / ,filePath.lastIndexOf( / )-1),filePath.lastIndexOf( / ));
返回文件夹Name 作为 whatsApp Vide
要获得上上一个字符串
This - https://developer.co/RTsMlGTsCj/share
To - RTsMlGTsCj
使用此
科特林
val removeDomainName : String = scanResult.substring(
scanResult.lastIndexOf( / , scanResult.lastIndexOf( / ) - 1),
scanResult.lastIndexOf( / )
)
val profileCode: String = removeDomainName.removePrefix("/")
爪哇
String removeDomainName = scanResult.substring(scanResult.lastIndexOf( / ,scanResult.lastIndexOf( / )-1),scanResult.lastIndexOf( / ));
Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...
Check this, List<String> list = new ArrayList<String>(); for (int i = 0; i < 10000; i++) { String value = (""+UUID.randomUUID().getLeastSignificantBits()).substring(3, ...
I am in the middle of solving a problem where I think it s best suited for a decorator and a state pattern. The high level setting is something like a sandwich maker and dispenser, where I have a set ...
I have been trying to execute a MS SQL Server stored procedure via JDBC today and have been unsuccessful thus far. The stored procedure has 1 input and 1 output parameter. With every combination I ...
I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...
If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...
I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....
I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...