0

生成 CSV。我正在尝试创建一个具有多个下一行的描述字符串。

我试过了 :

description = a.replaceAll("\n","\\\\n");

但是我得到了 \n 并且它没有出现在一行中

电流输出

IS0001;10381;Active Directory groups EU AD;SW;Internal applications;E\CIERORAD;CRP\E616053;16053;616053;radva.cierny@evry.com;E\XXJANDAM;CRP\E21494;7481;21494;ext.milsv.janda@evry.com;This tool allows users to view and manage delivery lists and groups in Active Directory. Everyone in EVRY will have access via https://int.eto.com
\n
\nAll users can view the distribution lists and security groups they are members of, with the exception of dynamic distribution lists. Dynamic distribution lists are based on Wo/ERP data, and they are usually for organizational units and some roles, e.g. line managers. 
\n
\nGroup owners can view and manage their groups, including renewing and deleting groups, and adding and removing members of these groups. 
\n
\nNew groups are created by requesting a group from My Support, there is no self-service for that.

期待:

IS0001;10381;Active Directory groups EU AD;SW;Internal applications;E\CIERORAD;CRP\E616053;16053;616053;radva.cierny@evry.com;E\XXJANDAM;CRP\E21494;7481;21494;ext.milsv.janda@evry.com;This tool allows users to view and manage delivery lists and groups in Active Directory. Everyone in EVRY will have access via https://int.eto.com \n\n All users can view the distribution lists and security groups they are members of, with the exception of dynamic distribution lists. Dynamic distribution lists are based on Wo/ERP data, and they are usually for organizational units and some roles, e.g. line managers. \n\nGroup owners can view and manage their groups, including renewing and deleting groups, and adding and removing members of these groups. \n\nNew groups are created by requesting a group from My Support, there is no self-service for that.

知道如何在一行中制作吗?

4

2 回答 2

1

使用实现

description = a.replace("\n", "\\\\n").replace("\r", "");
于 2021-06-28T11:09:38.720 回答
0

要用一个换行符替换多个换行符/回车符(任何顺序),我会使用:

replaceAll("[\n\r]+", "\n")

要真正创建一行(并用\+n代替换行符):

replaceAll("\\r?\\n|\\r", "\\\\n")
于 2021-06-28T12:47:02.807 回答