You can use String.Replace(from, to), in your case you can use it like this:
double size = Convert.ToDouble("12px".Replace("px", ""));
If you don’t want to use String.Replace() you can also do this:
string pixelSize = "12px";
double size = Convert.ToDouble(pixelSize.Remove(pixelSize.Length - 3));