Example #1
0
 public void AddLine(string srcLine)
 {
     if (!String.IsNullOrEmpty(srcLine))
     {
         lines.Add(CsvLine.Load(srcLine));
     }
 }
Example #2
0
        public static CSV Load(string srcText, char delimeter = ',')
        {
            if (IsSrcValid(srcText))
            {
                List <CsvLine> lines    = new List <CsvLine>();
                string[]       srcLines = srcText.Split('\n');

                foreach (string l in srcLines)
                {
                    lines.Add(CsvLine.Load(l.Trim(), delimeter));
                }

                CSV csv = new CSV();
                csv.lines.AddRange(lines);

                return(csv);
            }
            return(null);
        }
        private void btnCsvConvert_Click(object sender, RoutedEventArgs e)
        {
            if (txtRichCSV.Document.Blocks.Count > 0)
            {
                TextRange textRange = new TextRange(txtRichCSV.Document.ContentStart, txtRichCSV.Document.ContentEnd);

                string[] lines = textRange.Text.Split('\n');

                csv.ClearLines();

                foreach (string l in lines)
                {
                    string[] values  = l.Split('\t');
                    string   lineSrc = "";

                    foreach (string v in values)
                    {
                        if (!String.IsNullOrEmpty(v))
                        {
                            lineSrc += v;
                        }

                        if (v != values.Last())
                        {
                            lineSrc += ",";
                        }
                    }
                    if (!String.IsNullOrEmpty(lineSrc))
                    {
                        csv.AddLine(CsvLine.Load(lineSrc));
                    }
                }

                json = Converter.CsvToJson(csv);

                ClearBoxesAndDisableButtons();
                PopulateBoxes();
            }
        }