loadStrings and analysing the line, help?
in
Programming Questions
•
1 year ago
Hello and thanks for visiting my question,
What im trying to do is load a text document which has lots of lines of text and numbers (g-code to be exact). And i want to analyse each line and remove characters i dont want, then save this to a new text document.
The reason being is i have a custom made CNC and i want to take the G-Code and strip it so it only leaves the X Y and Z part. But the X Y and Z in the G-Code is arranged like this "X200 Y100 Z100" well i need it to be arranged like this "200X 100Y 100Z". I have this so far:
But im not sure on how to check each line for characters i dont want, and remove them. I need to remove a decimal point, numbers and letters but only when in a certain order. For example "N153" i want to remove that completly from the text document but only when its arranged in that order, otherwise it could delete the nubmers in the X Y Z cord.
Any help would be amazing.
Thanks,
Calum.
What im trying to do is load a text document which has lots of lines of text and numbers (g-code to be exact). And i want to analyse each line and remove characters i dont want, then save this to a new text document.
The reason being is i have a custom made CNC and i want to take the G-Code and strip it so it only leaves the X Y and Z part. But the X Y and Z in the G-Code is arranged like this "X200 Y100 Z100" well i need it to be arranged like this "200X 100Y 100Z". I have this so far:
- String[] lines; // file array
int index;
String current;
void setup(){
size(200, 200);
lines = loadStrings("GCode.txt");
println(Serial.list());
println("File is " + lines.length + " lines long");
}
void draw(){
if(index < lines.length){
current = lines[index];
println("Line " + index + ": " + lines[index]);
index = index + 1;
}
}
But im not sure on how to check each line for characters i dont want, and remove them. I need to remove a decimal point, numbers and letters but only when in a certain order. For example "N153" i want to remove that completly from the text document but only when its arranged in that order, otherwise it could delete the nubmers in the X Y Z cord.
Any help would be amazing.
Thanks,
Calum.
1