誰能幫我,如何從在紅寶石串的每一行刪除尾隨空格....例如:刪除紅寶石後從每行空格的字符串
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