Answer the question
In order to leave comments, you need to log in
How to properly process text in C#?
Task:
This text
...
X13.41Y-24.94
G00Z5.00
G00X7.28Y-33.17
G01Z0.00F600
G02X6.45Y-32.08I3.88J3.86
...
...
G5 X13.1 Y-24.94
G0 Z5.00
G0 X7.28 Y-33.17
G1 Z0.00
G2X 6.45 Y-32.08 I3.88 J3.86
...
Regex regex = new Regex(@"\.");
textBox1.Text = regex.Replace(textBox1.Text, ",");
Regex regzero = new Regex(@"F600");
textBox1.Text = regzero.Replace(textBox1.Text, "");
Regex regGX = new Regex(@"^X");
textBox1.Text = regzero.Replace(textBox1.Text, "G5X");
Regex regX = new Regex(@"X");
textBox1.Text = regzero.Replace(textBox1.Text, " X");
Regex regY = new Regex(@"Y");
textBox1.Text = regzero.Replace(textBox1.Text, " Y");
Regex regI = new Regex(@"I");
textBox1.Text = regzero.Replace(textBox1.Text, " I");
Regex regJ = new Regex(@"J");
textBox1.Text = regzero.Replace(textBox1.Text, " J");
...
G5 X13100 Y-24940 //assume these are the start coordinates
M98P0002 //replace G00Z5.00 with M98P0002
G0 X-5820 Y-9230 //the position of these coordinates relative to previous
M98P0003 //replace G01Z0.00 with M98P0003
G2X - 830 Y-1090 I3880 J3860 //parameters I and J do not need to be changed, only *1000
...
...
G5 X13100 Y-24940
M98P0002
G0 X-5820 Y-9230
M98P0003
G2X -830 Y-1090 I3880 J3860
...
Answer the question
In order to leave comments, you need to log in
Regex regex = new Regex(@"X(-?\d+)\.(\d+)Y(-?\d+)\.(\d+).*?G00Z(-?\d+)\.(\d+).*?G00X(-?\d+)\.(\d+)Y(-?\d+)\.(\d+).*?G01Z(-?\d+)\.(\d+).*?G02X(-?\d+)\.(\d+)Y(-?\d+)\.(\d+)I(-?\d+)\.(\d+)J(-?\d+)\.(\d+)", RegexOptions.Singleline);
textBox1.Text = regex.Replace(textBox1.Text, "G5 X$1,$2 Y$3,$4\nG0 Z$5,$6\nG0 X$7,$8 Y$9,$10\nG1 Z$11,$12\nG2 X$13,$14 Y$15,$16 I$17,$18 J$19,$20");
You must add the G5 parameter to the beginning of lines starting with coordinates (X or Y), and separate the parameters with a space.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question