我有以下内容:
api_response
=> "<parse>Awesome! It looks great to me!\n \n\n \n \n\n <SETPROFILE>\n <KEY>funnels.intro_funnel.edit_ME\nTHOD</KEY>\n <VALUE>done</VALUE>\n </SETPROFILE>\n \
n\n \n \n\n \n You alright if we add another method later?\n\n XHIDE YES NO ADD METHOD XHIDE</parse>\n"
我想要字符串如下:
"Awesome! It looks great to me! You alright if we add another method later? XHIDE YES NO ADD METHOD XHIDE"
我是怎么来到这里的:
我提取了原始api_response
并得到了以下数组:
["Awesome! It looks great to me!", "You alright if we add another method later?\n\n XHIDE YES NO ADD METHOD XHIDE"]
但我无法弄清楚如何将它串在一起。我使用.join(','),但现在有一个额外的,
。
问题:
a)如果我有这个数组,怎么能把它变成上面的字符串?
b)是否有更清洁的方法。我使用了XML提取库,但它输出非XML作为上面的数组。
答案 0 :(得分:0)
您需要按空格加入,而不是逗号:
a = ["Awesome! It looks great to me!", "You alright if we add another method later?\n\n XHIDE YES NO ADD METHOD XHIDE"]
a.join
#=> "Awesome! It looks great to me! You alright if we add another method later?\n\n XHIDE YES NO ADD METHOD XHIDE"
但在这里你会看到额外的新线条和额外的空间。要删除它,您可以再次split
和join
:
a.join.split.join(' ')
#=> "Awesome! It looks great to me! You alright if we add another method later? XHIDE YES NO ADD METHOD XHIDE"