【问题标题】:String Newline not displaying in Doors字符串换行符未显示在门中
【发布时间】:2019-04-04 10:08:05
【问题描述】:

我有一个 csv 文件,其中包含一些数据,例如:

374,Test Comment multiplelines \n Here's the 2nd line,Other_Data

其中 374 是来自门的对象 ID,然后是一些评论,然后是一些其他数据。 我有一段代码从 CSV 文件中读取数据,将其存储在适当的变量中,然后将其写入门对象。

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(),但转义字符就消失了。 我也尝试在输入的 csv 文本中添加 \r\n\\n,但仍然没有运气

【问题讨论】:

    标签: ibm-doors


    【解决方案1】:

    这不是处理此问题的最有效方法,但我有一个相对简单的解决方法。

    我建议添加以下内容:

    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”。请注意 - 这将忽略行尾的任何尾随空格。

    如果有帮助,请告诉我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-06-27
      • 2023-04-03
      • 2011-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-02
      相关资源
      最近更新 更多