Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, Im trying to get part of the data from an innerhtml in a website. specifically the price in this innerhtml:

Online Price: $15.31

I only need the 15.31 from this. How can I do it?

Thanks!
Posted
Comments
Kornfeld Eliyahu Peter 9-Feb-14 13:05pm    
Try RegEx...
♥…ЯҠ…♥ 10-Feb-14 2:55am    
Where do you wanna get value in server side or client side?

Refer - How to convert a currency string to a double with jQuery or Javascript?[^].
Quote:
Remove all non dot / digits:
JavaScript
var currency = "$1,100.00";
var number = Number(currency.replace(/[^0-9\.]+/g,""));
 
Share this answer
 
Comments
slayasty 9-Feb-14 13:46pm    
mm but in my case I have to type every character I dont want right?
Yeah, so what is the problem. Just replace the string with element's innerHTML or something, like...

var currency = document.getElementById("someFieldId").innerHTML;
Hi,

Use regular expression.

You may find appropriate example on blogs.

you may use match method.


example:
<HTML>
<BODY>
<script language="javascript" type="text/javascript">
alert("$3000.00onlyd".match(/\d+(\.\d+)/)[0]);
</script>
Done
</BODY>
</HTML>


Thanks
Chetan
 
Share this answer
 
v3
Comments
slayasty 9-Feb-14 15:46pm    
I cant seem to find any similar parameter to match since it is not showing in my visual studio :/
Ok I found the solution. Thanks everyone :)

Solution:

string getPrice = "Online Price $15.31";
getPrice = getPrice.Substring(15);

output = 15.31
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900