如何在Ruby中修改字符串?

时间:2014-03-14 07:44:34

标签: ruby string

如果我有这样的字符串:

a = "11003.20140314143116.11003#13947822765031.ssint1.natvoice_nowithin_2txns.translatedalreadytotxt.pdf"
b = "11003.20140314143454.11003#13947824943836.ssint1.natvoice_nowithin_2txns.translatedalreadytotxt.pdf"
c = "11003.20140303131136.11003#13938270964818.telstra-alltxns-live_stripped-1.translatedalreadytotxt.pdf"

...如何在Ruby中修改它们,结果如下:

a = "ssint1.natvoice_nowithin_2txns.translatedalreadytotxt.pdf"
b = "ssint1.natvoice_nowithin_2txns.translatedalreadytotxt.pdf"
c = "telstra-alltxns-live_stripped-1.translatedalreadytotxt.pdf"

1 个答案:

答案 0 :(得分:1)

所以你希望字符串以~z?

开头
result = a.gsub(/\A[^a-z]*/, '')

如果您想要更改原始字符串,请使用

a.gsub!(/\A[^a-z]*/, '')