Note
In the following code examples - for easier readability - exception handling has been omitted.
public static CsvRecord[] ParseAnalyzed(
string csv,
Header header = Header.ProbablyPresent,
int analyzedLines = 5
)
Public Shared Function ParseAnalyzed (
csv As String,
Optional header As Header = Header.ProbablyPresent,
Optional analyzedLines As Integer = 5
) As CsvRecord()
public:
static array<CsvRecord^>^ ParseAnalyzed(
String^ csv,
Header header = Header::ProbablyPresent,
int analyzedLines = 5
)
static member ParseAnalyzed :
csv : string *
?header : Header *
?analyzedLines : int
(* Defaults:
let _header = defaultArg header Header.ProbablyPresent
let _analyzedLines = defaultArg analyzedLines 5
*)
-> CsvRecord[]
CsvAnalyzer performs a statistical analysis on the String. The result of the analysis is therefore always only an estimate, the accuracy of which increases with the number of lines analyzed.
The field delimiters COMMA (',', %x2C), SEMICOLON (';', %x3B), HASH ('#', %x23), TAB ('\t', %x09), and SPACE (' ', %x20) are recognized automatically.
using FolkerKinzel.CsvTools;
namespace Examples;
internal static class CsvStringExample
{
public static void ConvertingCsvStrings()
{
object?[][] data =
[
[ "Color", "Direction", "Number"],
[ "brown", "right", 0],
["red", "left", 42],
[null, "Somewhere \"over\" the Rainbow"],
["""
Blue
in
Green
""", "Up, or down", -3.14]
];
string csv = data.ToCsv();
Console.WriteLine(csv);
Console.WriteLine();
CsvRecord[] results = Csv.ParseAnalyzed(csv);
foreach (CsvRecord record in results)
{
Console.WriteLine(record);
}
}
}
/*
Console Output:
Color,Direction,Number
brown,right,0
red,left,42
,"Somewhere ""over"" the Rainbow",
"Blue
in
Green","Up, or down",-3.14
Color: brown, Direction: right, Number: 0
Color: red, Direction: left, Number: 42
Color: , Direction: Somewhere "over" the Rainbow, Number:
Color: Blue
in
Green, Direction: Up, or down, Number: -3.14
*/
ArgumentNullException | csv is null. |
ArgumentOutOfRangeException | header is not a defined value of the Header enum. - or - header is a combination of Header values. |
CsvFormatException | Invalid CSV file. Try to increase the value of analyzedLines to get a better analyzer result! |