2014-03-14 84 views
-2

如果我有一個字符串是這樣的:如何在Ruby中修改字符串?

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

所以,你要的字符串A〜Z開頭?

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

如果你想改變原來的字符串,然後使用

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

謝謝@xdazz解決我的問題 – tardjo