本文整理汇总了C#中Encog.Util.CSV.CSVFormat.Parse方法的典型用法代码示例。如果您正苦于以下问题:C# CSVFormat.Parse方法的具体用法?C# CSVFormat.Parse怎么用?C# CSVFormat.Parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Encog.Util.CSV.CSVFormat
的用法示例。
在下文中一共展示了CSVFormat.Parse方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FromList
/// <summary>
/// Get an array of double's from a string of comma separated text.
/// </summary>
/// <param name="format">The way to format this list.</param>
/// <param name="str">The string that contains a list of numbers.</param>
/// <returns>An array of doubles parsed from the string.</returns>
public static double[] FromList(CSVFormat format, String str)
{
if( str.Trim().Length==0)
{
return new double[0];
}
// first count the numbers
String[] tok = str.Split(format.Separator);
int count = tok.Length;
// now allocate an object to hold that many numbers
var result = new double[count];
// and finally parse the numbers
for (int index = 0; index < tok.Length; index++)
{
try
{
String num = tok[index];
double value = format.Parse(num);
result[index] = value;
}
catch (Exception e)
{
throw new PersistError(e);
}
}
return result;
}
示例2: FromList
public static double[] FromList(CSVFormat format, string str)
{
if (str.Trim().Length != 0)
{
string[] strArray = str.Split(new char[] { format.Separator });
int length = strArray.Length;
double[] numArray = new double[length];
for (int i = 0; i < strArray.Length; i++)
{
try
{
string str2 = strArray[i];
numArray[i] = format.Parse(str2);
}
catch (Exception exception)
{
throw new PersistError(exception);
}
}
return numArray;
}
return new double[0];
}
示例3: Analyze
/// <summary>
/// Analyze the input file.
/// </summary>
/// <param name="input">The input file.</param>
/// <param name="headers">True, if there are headers.</param>
/// <param name="format">The format of the CSV data.</param>
public virtual void Analyze(FileInfo input, bool headers,
CSVFormat format)
{
ResetStatus();
InputFilename = input;
ExpectInputHeaders = headers;
Format = format;
_columnMapping.Clear();
_columns.Clear();
// first count the rows
TextReader reader = null;
try
{
int recordCount = 0;
reader = new StreamReader(InputFilename.OpenRead());
while (reader.ReadLine() != null)
{
UpdateStatus(true);
recordCount++;
}
if (headers)
{
recordCount--;
}
RecordCount = recordCount;
}
catch (IOException ex)
{
throw new QuantError(ex);
}
finally
{
ReportDone(true);
if (reader != null)
{
try
{
reader.Close();
}
catch (IOException e)
{
throw new QuantError(e);
}
}
InputFilename = input;
ExpectInputHeaders = headers;
Format = format;
}
// now analyze columns
ReadCSV csv = null;
try
{
csv = new ReadCSV(input.ToString(), headers, format);
if (!csv.Next())
{
throw new QuantError("File is empty");
}
for (int i = 0; i < csv.ColumnCount; i++)
{
String name;
if (headers)
{
name = AttemptResolveName(csv.ColumnNames[i]);
}
else
{
name = "Column-" + (i + 1);
}
// determine if it should be an input/output field
String str = csv.Get(i);
bool io = false;
try
{
Format.Parse(str);
io = true;
}
catch (FormatException ex)
{
EncogLogging.Log(ex);
}
AddColumn(new FileData(name, i, io, io));
}
}
finally
//.........这里部分代码省略.........