Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2140
  • Last Modified:

Parse String and get all float number and put into array-java

For example i have a string : [(123.4,5.6,7.8),(1.5,6.7,1.2),(2.3,4.5,6.7)]
How ican i put  the float numbers into array?
array[0]=123.4;
array[1]=5.6;
....and so on...

Thank you
0
cipriancomsa
Asked:
cipriancomsa
  • 2
  • 2
1 Solution
 
ahoffmannCommented:
java.util.regex is your friend
0
 
cipriancomsaAuthor Commented:
I tried with float f = Float.parseFloat(str);
System.out.println(f);
but i have many errors.
0
 
ahoffmannCommented:
just giving *this* string to parseFloat might not be a good solution, most likely causing errors or improper results
Regex, as said before, is your friend (at least one) ...
0
 
cipriancomsaAuthor Commented:
package notepad;
public class StringSplit {

   public double[] doit(String instr) {


      double[] rez=new double[3];
      String[] temp=null;

      boolean bool=testFirst(instr);

   
      if(bool){


      temp = instr.split("\\[");
      temp = temp[1].split("\\]");

      temp = temp[0].split("\\(");
      temp = temp[1].split("\\)");

      temp = temp[0].split("\\,");

      }

      for(int i=0;i< temp.length; i++){
           Double db=new Double(temp[i]);
           double d=db.doubleValue();
           rez[i]=d;
      }
          return rez;

      }
     
     
public void dump(double[] s) {
    System.out.println("------------");
    for (int i = 0 ; i < s.length ; i++) {
        System.out.println(s[i]);
    }
    System.out.println("------------");
}

}
This is the solution of my problem .I put this code for whio have the same problem with me.
0

Featured Post

Who's Defending Your Organization from Threats?

Protecting against advanced threats requires an IT dream team – a well-oiled machine of people and solutions working together to defend your organization. Download our resource kit today to learn more about the tools you need to build you IT Dream Team!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now