Subset() on a string gives "cannot convert object to string" error - but why?
in
Programming Questions
•
2 years ago
As far as I can tell I'm using the SUBSET method correctly to trim the first character out of a string. Obviously I'm not however, as I keep getting a "cannot convert object to string" error, but can't see what's wrong with my code, despite logn extensive searches on this topic.
Here's the code. Any feedback is very much appreciated.
- String[] lines = loadStrings("test.txt"); // load test gcode file
- print("There are " + lines.length + " lines in the file");
- for ( int i=0; i<lines.length; i++){ //cycle through the file line at a time
- String[] list = trim(split(lines[i], ' ')); //split the line into space=delimited snippets
- for (int n=0; n<list.length; n++) { //cycle through the snippets
- if(list[n].indexOf("X")!=-1) {
- String xval = list[n];
- int xlen = xval.length()-1;
- String xnum = subset(xval, 1, xlen); // THIS IS WHERE I GET THE ERROR
- println(list[n]);
- } else {
- if (list[n].indexOf("Y")!=-1) {
- println(list[n]);
- }else {
- if (list[n].indexOf("Z")!=-1) {
- println(list[n]);
- }
- }
- }
- text(lines[i], 20, i*30, 50+1*30);
- }
- }
1