c# - How can I edit Strings with unknown delimiters -


I have to write a converter for CNC machine code.

I find it hard to follow the examples of reggae and its specially "delimiter" -the belief in the creation of others.

I'm struggling to partially remove the string (from the letter "Z" to the end of the line), in fact this is what I have found and must change it:

< Pre> N11 G0 X49.000 Y30.329 Z0.000 N12 G X450 Y30.329 Z-1.000 N13 G1 X49.000 Y50 .32 9 Z-1.000 F500 N14 X49.000 Y150.000 Z0 .000 N15 X49.300 Y150.700 Z-15000 F400 N16 X50,000 Y151.000 Z + 1000,000 N17 X150.000 Y151.000 Z-1.000

The result should be:

  N11 G0 X49.000 Y30.329 A49.000 B30.329 N12 G0 X49.000 Y30.329 A49.000 B30.329 N 13 G1 X 49,000 Y50.329 A 49,000 B50.329 F 500 N 14 X 49,000 Y150,000 A 49,000 B1 50,000 NAR 154940000 Ï 1 50.700 A 49.300 b 150.700 F 400 N 16 x 50,000 y151.000 A50.000 B151,000 N17 X150.000 Y151.000 A150.000 B151.000  

This is a repetition Where I want to edit those strings:

 for  (int i = 11; i & lt; oldizo langti; i ++) {converted. Appendline (remove batin (old iso [ii], 'z', endofline); }  

So I'm not sure I can get it as good as possible. I thought of removing the "Z" character from the end of the line. I will take care of the "F500 / F400" lines - later similar to A and Bs X and YS values, quite different.

One way you can do this - suppose that the format you posted above is reliable and Is consistent - the string is to be divided into an array of space-delimited strings

"N12 G0 X49"

This might look like this: / P>

000 Y30.329 Z-1.000 "; string [] splitLine = line.Split (new four [] {'}}, string split option. RemoveEmptyEntries;); StringBuilder stringbilder = new stringbiller (); Foreach (In splitLine String split string) {if (split string [0]! = 'Z') {// Do not forget to add stringbilder back to the spaces. Append (splitString + "");}} string string = stringBuilder.ToString (); It may be off-base - you have said that the delimiters are unknown, but each row you post as a sample is estimated to be delimited. You also want to remove, will work with it - albeit - if If you decide that you do not want to start with F, then add it conditional to the original, such as:

  if (splitString [0]! = 'Z' & amp; Split string [0]! = 'F' / * and etc. and etc. * /)  

A and B segments we need a bit more information about 'D', and partly like a different question looks like. For starters, we have to know whether it counts that the lines are formatted (XYAB) in the order shown by you or can these tokens be present at any point in the string.


Comments