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

SQL Query Help: Selecting Rows That Appear A Certain Number Of Times

sql date select

I have a table with a "Date" column. Each Date may appear multiple times. How do I select only the dates that appear &lt; k number of times?

How does gdb attach to multi-threaded process?

c++ multithreading gdb

I will try to be as specific as I can, but so far I have worded this problem so poorly that Google failed to return any useful results (hence my question here).