Split String of Accel Values and save what is split - Java

I want to split a string with Accelerometer values into each axis (x,y,z). However, the data is constantly changing so there is no set value for split() to search through. I need it to search through the string, take out the axes to separate strings, then save them.

Here's my code, which just saves the whole string to a file:

try {
            PrintWriter writer = new PrintWriter(new BufferedWriter(
                    new FileWriter("/sdcard/YS Data/Accelerometer.html",
                            true)));
            writer.println("<h3 style=padding-left:20px;>" + text
                    + "</h3><br>");
            writer.flush();


            writer.close();
        } catch (IOException e) {

            e.printStackTrace();


        }

I've tried

String[] array = writer.split("y");

to get from the y value on, but it says I have to add a cast, which when I add

((String) writer).split("x");

gives me an error. (Cannot cast from PrintWriter to String)

Basically, because I know there is and x,y and z in the string, I was thinking if first I take all of the data in the text string (that contains all sensor data) from x on and put it in a new string, then split that string from y on into another string, then from that split z off to another string. That way I'd have three strings, one for x, y and z.

Thanks,

Answers


Try this :    

                String axis="x=-0.125 y=0.9375 z=0.375";
                String[] tempArr=axis.split(" ");
                ArrayList arr=new ArrayList<String>();
                for(String a:tempArr){
                    arr.add(a.split("=")[1].trim());
                }
                System.out.println(arr);

this will sperate the all the values of x,y&z


I know there is and x,y and z in the string, I was thinking if first I take all of the data in the text string (that contains all sensor data) from x on and put it in a new string, then split that string from y on into another string, then from that split z off to another string. That way I'd have three strings, one for x, y and z.

What you are saying is corrent . You have to do like this only.


Need Your Help

How do I get a list of tables affected by a set of stored procedures?

database stored-procedures

I have a huge database with some 100 tables and some 250 stored procedures. I want to know the list of tables affected by a subset of stored procedures. For example, I have a list of 50 stored

Exception when adding a ResourceDictonary at runtime

silverlight windows-phone-7 resourcedictionary windows-phone

I'm trying to develop a way of switching Windows Phone 7 application style depending on a setting.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.