String text = "Thanx for purchasing this, Rs. 1000. Thanx for visiting";
I need double value from the above string.
Length is not fixed of Rs. value (1000
).
How to get this value?
String text = "Thanx for purchasing this, Rs. 1000. Thanx for visiting";
I need double value from the above string.
Length is not fixed of Rs. value (1000
).
How to get this value?
For this you need to use java regex
Here is sample code
Regex pattern will change based on your requirement simple regex to get only double value "\\d+\\.\\d+"
String line = "Thanx for purchasing this, Rs. 1000. Thanx for visiting";
String regex = "[+-]?\d*\.?\d+([eE][+-]?\d+)?";
String[] str = line.split(regex);
Other wise you can try below code
public String drawDigitsFromString(String strValue){
String str = strValue.trim();
String digits="";
for (int i = 0; i < str.length(); i++) {
char chrs = str.charAt(i);
if (Character.isDigit(chrs))
digits = digits+chrs;
}
return digits;
}
I think this will help you.
if there is no other number then After Rs. you can use
text.replaceAll("[^0-9]", "");
if there is some other number also, it will fail.
You can make an array of all the words and the use only the number like this:
var text = "Thanx for purchasing this, Rs. 1000. Thanx for visiting";
var array = text.split(" ");
var newText = array[5].replace(".","");
console.log(newText)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>