【发布时间】:2012-10-30 14:31:28
【问题描述】:
我正在我的 c# 应用程序中创建一个长字符串。我希望它保持在一行,因为这些是用户选择在数据库中更新的字段的标题。 该字符串将在日志文件中使用。
当我选择所有要更新的字段时,似乎字符串太长而无法在一行中显示并自动换行。
我很困惑,因为 textfile 应该能够处理任意长度的字符串(内存允许)而无需换行。
似乎一旦字符串长度超过大约 1050 个字符,它就会自动换行。
我的代码如下:
private void UpdateCustomer(string pCurrentFileName, ref StringBuilder log, string date, ref string directoryPath, ref string logFilePath)
{
// set the logfile paths for customer update
directoryPath = Path.Combine(pLogFilePath, "CustomerUpdate_Log_" + date.Replace("/", "").Replace(" ", "").Replace(":", ""));
logFilePath = Path.Combine(directoryPath, "CustomerUpdate.log");
DataSet customerUpdateDataSet = new CustomerUpdateValidator().ImportCustomersForUpdateFromExcelFileToDataSet(pCurrentFileName);
log.Append("-------------------------------------------------------------------------" + "\r\n");
log.Append("Bulk Maintenance Log: Customer Updatess" + "\r\n");
log.Append("-------------------------------------------------------------------------" + "\r\n");
log.Append(date + "\r\n\r\n");
log.Append("Total number of Customer to be updated: " + (customerUpdateDataSet.Tables["CustomerData"].Rows.Count - 2).ToString() + "\r\n\r\n");
log.Append("Data to be Inserted" + "\r\n");
log.Append("-".PadRight(300, '-') + "\r\n\r\n\r\n");
StringBuilder header = new StringBuilder("Row".PadRight(10, ' ') + "\t");
header.Append("URN".PadRight(40, ' ') + "\t");
int count = 0;
// for each row in the grid view
for (int i = 0; i < this.gridView1.DataRowCount; i++)
{
// if the value is checked
if (Convert.ToBoolean(this.gridView1.GetRowCellValue(i, "CheckMarkSelection")))
{
// get the fields from the checked column
string baxiDescription = this.gridView1.GetRowCellValue(i, "SimpleName").ToString();
int size = getSizeFromType(this.gridView1.GetRowCellValue(i, "Type").ToString());
header.Append(baxiDescription.PadRight(size, ' ') + "\t");
count = i;
}
}
header.Append("Result".PadRight(10, ' ') + "\t");
header.Append("Reason".PadRight(30, ' ') + "\t");
log.Append(header.ToString() + "\r\n");
log.Append(new StringBuilder("-".PadRight(header.Length + 60, '-') + "\r\n"));
}
任何想法为什么会发生这种情况?
我的数据集:
包装的日志文件:
【问题讨论】:
-
听起来可能是客户端问题,而不是数据的一部分。你用什么显示这个?
-
同意 Jon 的观点,在十六进制查看器或显示 CR-LF 的东西中查看是否真的有换行符。
-
@Jon Skeet 我在 memoedit devexpress 控件中显示它。它也被保存为一个文本文件,它在字符串中与备忘录编辑完全相同的点处换行。我注意到在调试过程中它也在监视窗口中做同样的事情
-
在这种情况下,听起来数据本身可能包含换行符。
-
@Jon Skeet 好的,我在 Ultra 编辑中检查了生成的日志文件,格式很好,所以您认为这是客户端问题是正确的。关于如何让记事本正确显示的任何建议?