谁能帮我,如何从在红宝石串的每一行删除尾随空格....例如:删除红宝石后从每行空格的字符串
str = "Hello everyone. \nHope you guys are doing good \nstrange i can't remove this spaces"
我试着rstrip,但它不适合我....可能必须尝试gsub ....我希望答案在下面wayy。
"Hello everyone.\nHope you guys are doing good\nstrange i can't remove this spaces"
rstrip在字符串的末尾剥离空格,而不是在每行的末尾。你可以使用正则表达式在每个'\ n'之前进行替换。 – jcoppens