简体   繁体   English

如何在Java / Android中从String结束?

[英]How do I take the end off of a String in Java/Android?

I have a string that looks like this: 我有一个看起来像这样的字符串:

http%3A%2F%2Fwww.myurl.com%2Fbarcodes%2Fimages%2F024543634737.jpg

I just want the end of the string past the / (%2F) so I get the following: 我只希望字符串的结尾超过/(%2F),所以得到以下信息:

024543634737.jpg

Is there a RegEx or something that I can use with Java? 是否存在RegEx或我可以在Java中使用的东西? Can someone post some quick code? 有人可以发布一些快速代码吗?

String splitString = "/"; // you can change it to %2F
String s = "http://www.myurl.com/barcodes/images/024543634737.jpg";
int index = s.lastIndexOf(splitString);
String result= null;
if(index > -1){
    result = s.substring(index+splitString.length());
}

Try the following (using String.lastIndexOf and String.substring methods) - 尝试以下操作(使用String.lastIndexOfString.substring方法)-

String input = "http%3A%2F%2Fwww.myurl.com%2Fbarcodes%2Fimages%2F024543634737.jpg";
System.out.println(input.substring(input.lastIndexOf("%2F") + 3));

Output: 输出:

024543634737.jpg 024543634737.jpg

you can use lastIndexOf() method of String class. 您可以使用String类的lastIndexOf()方法。 lastIndexOf() Searches for the last occurrence of a character or substring. lastIndexOf()搜索字符或子字符串的最后一次出现。 see like this, 看到这样

String str = "http%3A%2F%2Fwww.myurl.com%2Fbarcodes%2Fimages%2F024543634737.jpg";

int i = str.lastIndexOf("%");

String result = str.substring ( i );
String[] array= "http%3A%2F%2Fwww.myurl.com%2Fbarcodes%2Fimages%2F024543634737.jpg".split("%2F");

String own = array[array.length-1];
if(myString.indexOf("/")>=0){  
    myString = myString.substring(myString.lastIndexOf("/")+1, myString.length());
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何将前导辅音移动到字符串的末尾? - How do I take the leading consonants an move them to the end of the string? 如何在Java中定义字符串的结尾? - How do I define the end of a string in Java? 如何在java中输入并打印整个字符串? - How do I take input and print the whole string in java? 如何去掉 Java 的 XOM 库中的 XML 版本标签? - How do I take off the XML version tag in the XOM library for Java? Java:切断字符串结尾的更简单方法 - Java: simpler way of cutting off end of string 如何获取带有命名组的字符串并仅用 Java 7 中的值替换该命名捕获组 - How do I take a string with a named group and replace only that named capture group with a value in Java 7 如何将字符串传递给Ant java? 我的程序不知何故不带空格 - How do I pass a string into Ant java? Somehow my program does not take arguments with white spaces java - 如何获取String数组的某些元素并创建一个新数组java - How do I Take certain elements of a String array and create a new array java Android-Volley:如何获取String响应值并将其分配到Volley StringRequest方法之外? - Android-volley: how do I take the String response value and assign it outside of a volley StringRequest method? 我如何进行像5'3“ 1/2的测量,然后将其乘以1.414,并在Android Java上以相同格式显示答案 - how do i take a measurement like 5' 3"1/2 and then multiply it by 1.414 and display answer in same format on android java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM