function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Lee_CampbellLee_Campbell 

"Finding" doubles in strings

Hi all,

 

I was wondering if it's possible to do a "double.valueof(string)" and avoid the "Invalid Double" error if my string is something like:

 

"3 is the magic number"

 

My string will always begin with a number (just trust me, it will), but it could be of any length, so I can't use "substring". Any ideas?

 

Thanks,

Lee

Best Answer chosen by Admin (Salesforce Developers) 
Damien_2Damien_2

Try doing something like:

 

Double.valueOf(myString.split(' ')[0]);

 

All Answers

Damien_2Damien_2

Try doing something like:

 

Double.valueOf(myString.split(' ')[0]);

 

This was selected as the best answer
Lee_CampbellLee_Campbell

Perfect!

 

Thanks very much.