-3

I want determine number from specify string.

Ex: I have many text strings, such as "3.2p" or "3.2px" or "xp3.2" or "p3.2x".

The final result I want is can get number from text in above. Expected result "3.2".

People who know,

Please help me,

Thanks,

Huy Tower
  • 7,769
  • 16
  • 61
  • 86
Dong Le
  • 107
  • 2
  • 12

2 Answers2

1

I would first remove all the non-numeric characters using a regex, then parse what remains.

String str = input.replaceAll("[^\\d.]", "");

Float.parseFloat(str);
starf
  • 1,063
  • 11
  • 15
1

Use this:

String s = "ffffa32.334tccy";
s = s.replaceAll("[^\\d.]", "");
Robi Kumar Tomar
  • 3,418
  • 3
  • 20
  • 27