I am writing java code for translating signals. If a given string (INPUT) is:
C*12.387a0d14assc7*18.65d142a
Its translation (OUTPUT) should be:
C*12387:1000a0d14assc7*1865:100d142a
ALGORITHM:
Wherever in the string a star(*) follows a number containing decimal (in this string there are two, first is '*12.387' and the second is *18.65'), this number is to be changed into fraction as in the above example 12.387 is converted into 12387:1000 and 18.65 converted into 1865:100
If decimal number is isolated I can convert it into fraction with the following code:
double d = 12.387;
String str = Double.toString(d);
String[] fraction = str.split("\\.");
int denominator = (int)Math.pow(10, fraction[1].length());
int numerator = Integer.parseInt(fraction[0] + "" + fraction[1]);
System.out.println(numerator + ":" + denominator);
But I do not how to separate the substring of decimal number from the string it contains. Being new to java and programming I need help. Thanks in anticipation.