我有包含一些数据的csv文件,如下所示:
374,Test Comment multiplelines \n Here's the 2nd line,Other_Data其中374是来自doors的对象ID,然后是一些注释,然后是一些其他数据。我有一段代码,它从CSV文件读取数据,将其存储在适当的变量中,然后将其写入doors对象。
Module Openend_module = edit("path_to_mod", true,true,true)
Object o ;
Column c;
string attrib;
string oneLine ;
string OBJECT_ID = "";
string Comment = "";
String Other_data = "";
int offset;
string split_text(string s)
{
if (findPlainText(s, sub, offset, len, false))
{
return s[0 : offset -1]
}
else
{
return ""
}
}
Stream input = read("Path_to_Input.txt");
input >> oneLine
OBJECT_ID = split_text(oneLine)
oneLine = oneLine[offset+1:]
Comment = split_text(oneLine)
Other_data = oneLine[offset+1:]使用print Comment时,DXL控制台中的输出为:Test Comment multiplelines \n Here's the 2nd line
for o in Opened_Module do
{
if (o."Absolute Number"""==OBJECT_ID ){
attrib = "Result_Comment " 2
o.attrib = Comment
}
}但在写入doors对象后,不考虑\n,结果如下:

我尝试过将字符串放入缓冲区并使用stringOf(),但是转义字符就这样消失了。我还尝试将\r\n和\\n添加到输入的csv文本中,但仍然没有成功
发布于 2019-04-05 01:45:54
这不是处理这个问题的最有效的方法,但我有一个相对简单的解决方法。
我建议添加以下内容:
Module Openend_module = edit("path_to_mod", true,true,true)
Object o ;
Column c;
string attrib;
string oneLine ;
string OBJECT_ID = "";
string Comment = "";
String Other_data = "";
int offset;
string split_text(string s)
{
if (findPlainText(s, sub, offset, len, false))
{
return s[0 : offset -1]
}
else
{
return ""
}
}
Stream input = read("Path_to_Input.txt");
input >> oneLine
OBJECT_ID = split_text(oneLine)
oneLine = oneLine[offset+1:]
Comment = split_text(oneLine)
Other_data = oneLine[offset+1:]
//Modification to comment string
int x
int y
while ( findPlainText ( Comment , "\\n" , x , y , false ) ) {
Comment = ( Comment [ 0 : x - 1 ] ) "\n" ( Comment [ x + 2 : ] )
}这将通过解析器运行注释字符串,将字符串"\n“替换为字符'\n‘。请注意-这将忽略行尾的所有尾随空格。
如果有帮助,请告诉我。
https://stackoverflow.com/questions/55513270
复制相似问题