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...
While there are many answers. Here is a regex example
Explanation:
.+
matches any character (except for line terminators)+
Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)=
matches the character = literally (case sensitive)This is also a shady copy paste from https://regex101.com/ where you can try regex out.
You can split the string from the = and separate in to array and take the second value of the array which you specify as after the = sign For example:
String CurrentString = "Fruit = they taste good"; String[] separated = CurrentString.split("="); separated[0]; // this will contain "Fruit" separated[1]; //this will contain "they teste good"
then separated[1] contains everything after = in the original string.
You can use
.substring()
:then
s1
contains everything after=
in the original string.s1.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).Maybe locate the first occurrence of the character in the URL String. For Example:
Then, split the String based on an index
String Result now contains the value: stringTest