如何删除Java中特定字符之前的所有字符? [英] How to remove all characters before a specific character in Java?
问题描述
我有一个字符串,我通过 html 表单获取值,所以当我获取值时,它出现在 URL 中,所以我想删除特定字符之前的所有字符,即 =
我也想删除这个字符.我只想保存 =
之后的值,因为我需要从变量中获取该值..
I have a string and I'm getting value through a html form so when I get the value it comes in a URL so I want to remove all the characters before the specific charater which is =
and I also want to remove this character. I only want to save the value that comes after =
because I need to fetch that value from the variable..
我也需要删除 =
,因为我试图在它之后获取字符串中的字符/值...
EDIT : I need to remove the =
too since I'm trying to get the characters/value in string after it...
推荐答案
你可以使用 .substring()
:
String s = "the text=text";
String s1 = s.substring(s.indexOf("=")+1);
s1.trim();
then s1
包含原始字符串中 =
之后的所有内容.
then s1
contains everything after =
in the original string.
.trim()
删除字符串(前导空格)的第一个字符(不是空格,例如字母、数字等)之前的空格,并删除最后一个字符之后的空格字符(尾随空格).
.trim()
removes spaces before the first character (which isn't a whitespace, such as letters, numbers etc.) of a string (leading spaces) and also removes spaces after the last character (trailing spaces).
这篇关于如何删除Java中特定字符之前的所有字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!