public static string ST_Znach(string S) { bool isNeedDot = true; string RED = "XYZ"; // Редактируемые значения string S2 = "YZABCF"; // string V = string.Empty; // строка на выходе string U, C; int a = 0, b = 0; // a - первое вхождение RED (начало числа) // b - первое вхождение S2 (конец числа) var printer = new NumberPrinter(isNeedDot, 2); for (int i = 0; i < RED.Length; i++) { a = S.IndexOf(RED[i]); V += S.Substring(b, a + 1); for (int j = 0; j < S2.Length; j++) { b = S.IndexOf(S2[j]); C = S.Substring(a + 1, b - a - 1); C = printer.Print(float.Parse(C)); S = S.Substring(a + 1, S.Length - a - 1); V += C; } } return(V); }
static void Main(string[] args) { string SS = "G0 X500.2365 Y300.12354 Z-50.25648 F2500"; ST_Znach(SS); List <double> test = new List <double>() { 0.1000f, 0.00100f, 115f, 1234.5678f, 0.0126f, .0789f }; bool isNeedDot = false; string writePath = @"C:\Users\ЮРИЙ\eclipse-workspace\COMPACT\ttt.cnc"; try { using (StreamWriter sw = new StreamWriter(writePath, false, System.Text.Encoding.Default)) { float v = float.Parse("234.456", CultureInfo.InvariantCulture); var printer = new NumberPrinter(isNeedDot, 2); sw.WriteLine(printer.Print(v)); } { //sw.WriteLine(text); // var printer = new NumberPrinter(isNeedDot, 2); // foreach (var value in test) // sw.WriteLine(printer.Print(value)); } } catch (Exception e) { Console.WriteLine(e.Message); } { //bool isNeedDot = true; //Console.WriteLine("DOT - 1"); //var printer = new NumberPrinter(isNeedDot, 1); //foreach (var value in test) // Console.WriteLine( printer.Print(value)); // Console.WriteLine("DOT - 2"); //printer = new NumberPrinter(isNeedDot, 2); //foreach (var value in test) // Console.WriteLine(printer.Print(value)); //Console.WriteLine("DOT - 3"); //printer = new NumberPrinter(isNeedDot, 3); // foreach (var value in test) // Console.WriteLine(printer.Print(value)); // Console.ReadKey(); } }
static void Main(string[] args) { List <double> test = new List <double>() { 0.1, 10, 115, 1234.5678, 0.0126, .0789 }; bool isNeedDot = true; Console.WriteLine("DOT - 1"); var printer = new NumberPrinter(isNeedDot, 1); foreach (var value in test) { Console.WriteLine(printer.Print(value)); } Console.WriteLine("DOT - 2"); printer = new NumberPrinter(isNeedDot, 2); foreach (var value in test) { Console.WriteLine(printer.Print(value)); } Console.WriteLine("DOT - 3"); printer = new NumberPrinter(isNeedDot, 3); foreach (var value in test) { Console.WriteLine(printer.Print(value)); } isNeedDot = false; Console.WriteLine("W/O DOT - 1"); printer = new NumberPrinter(isNeedDot, 1); foreach (var value in test) { Console.WriteLine(printer.Print(value)); } Console.WriteLine("W/O DOT - 2"); printer = new NumberPrinter(isNeedDot, 2); foreach (var value in test) { Console.WriteLine(printer.Print(value)); } Console.WriteLine("W/O DOT - 3"); printer = new NumberPrinter(isNeedDot, 3); foreach (var value in test) { Console.WriteLine(printer.Print(value)); } Console.ReadKey(); }
static void Main(string[] args) { //// ГОТОВАЯ ПРОГРАММА /* * if (args.Length != 5) * { * Console.WriteLine("Неверное количество параметров. Нужно 6: 1.dot{0,1} 2.количество знаков{1,2,3} 3.delta X {число с точкой} 4.delta Y {число с точкой} 5. delta Z {число с точкой} 6. Путь к файлу"); * return; * } * bool isNeedDot = true; * if (args[0] == "1") * isNeedDot = true; * else if (args[0] == "0") * isNeedDot = false; * else * { * Console.WriteLine("Неверное значение параметра IsNeedDot"); * } * * int countAfterDor = int.Parse(args[1]); * * var printer = new NumberPrinter(isNeedDot, countAfterDor); * * double deltaX = double.Parse(args[2], NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture); * double deltaY = double.Parse(args[3], NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture); * double deltaZ = double.Parse(args[4], NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture); * * string Path = args[5]; // открыть и прочитать файл в FileContent * string FileContent = "G0 X500.2365 Y300.12354 Z-50.25648 F2500"; * * string result = FileContent; * * result = StrategyForCoordinateStart('X', result, deltaX, printer); * result = StrategyForCoordinateStart('Y', result, deltaY, printer); * result = StrategyForCoordinateStart('Z', result, deltaZ, printer); * * Console.WriteLine(result);*/ ///ТЕСТОВАЯ ПРОГРАММА string FileContent = @"X500.2365 G0 X500.2365 Y300.12354 Z-50.25648 F2500 G0 X500.2365 Y300.12354 Z-50.25648 G0 X500.2365 Y300.12354 Z-50.25648 F2500"; FileContent = "G0 X500.2365Y300.12354Z-50.25648 F2500 G0 X500.2365Y300.12354Z-50.25648"; FileContent = File.ReadAllText(@"c:\work\samples\jury\WINNER IJK.anc"); var printer = new NumberPrinter(true, 2); string result = FileContent; result = StrategyForCoordinateStart('X', result, -100, printer, 0); result = StrategyForCoordinateStart('Y', result, 100, printer, 0); result = StrategyForCoordinateStart('Z', result, 0, printer, 0); Console.WriteLine(result); }
static string StrategyForCoordinateStart(char cords, string data, double delta, NumberPrinter printer, double minValue) { var parser = new ValueFinder(cords, delta, data, printer, minValue); return(parser.Process()); }