我有一串带有换行的数据。
例如:
"Product Name \n Product Color \n Product Quantity \n Product Location \n Product Size \n Product Power"
字符串中的元素数量可能是无限的。
我需要将\n
替换为>>>> \n
,但仅当行号大于3且不是最后一行时才需要替换。在最后一行上,我需要它显示(end)
我已经尝试使用map进行分割和替换,但我无法遍历数组以识别要修改的行,也无法在所有行被修改或未被修改时将它们重新连接起来。
输入为:
"Retract-A-Banner\n**Template:\nFull Color\nImprint Information:\nCL: 488 Special Ops Wing\n353 SOW Integrated Resilience Optimization Network\n"
期望的输出:
"Retract-A-Banner\n**Template:\nFull Color >>>> \nImprint Information: >>>> \nCL: 488 Special Ops Wing >>>> \n353 SOW Integrated Resilience Optimization Network(end)\n"