public static string ExecXYZ(string filepath, string separator = " ", string pathaddition = "some") { string filename = Filename.FromFullPath(filepath); string filedir = Filename.FolderFromFullPath(filepath); string new_name = Path.Combine(filedir, pathaddition + filename).Replace(".txt", ".pcd"); StreamWriter output = new StreamWriter(new_name); output.Write(string.Format(header, CountLines.CountLinesReader(new FileInfo(filepath)))); using (var input = new StreamReader(filepath)) { string input_line = ""; while ((input_line = input.ReadLine()) != null) { if (input_line.Contains("# .PCD v.7 - Point Cloud Data file format")) { return(""); } string[] parts = input_line.Split(separator); double x = double.Parse(parts[0]); double y = double.Parse(parts[1]); double z = double.Parse(parts[2]); input_line = string.Format("{0:F5} {1:F5} {2:F5}", x, y, z); output.WriteLine(input_line); } input.Close(); } output.Close(); return(new_name); /*string[] lines = File.ReadAllLines(filepath); * * if (lines[0].Contains("# .PCD v.7 - Point Cloud Data file format")) { * return ""; // the file has already been processed * } * * for (int i = 0; i < lines.Length; i++) { * string[] parts = lines[i].Split(separator); * double x = double.Parse(parts[0]); * double y = double.Parse(parts[1]); * double z = double.Parse(parts[2]); * // double colour = threeValRgbToOneVal(parts[3], parts[4], parts[5]); * lines[i] = string.Format("{0:F5} {1:F5} {2:F5}", x,y,z); * } * File.WriteAllText(filepath.Replace(".txt", ".pcd"), string.Format(header, lines.Length, string.Join("\n", lines))); * return filepath.Replace(".txt", ".pcd");*/ }