yuin #861(2007/07/14 18:05 GMT) [ Scala ] Rating0/0=0.00
実際には日本語でコケますが・・・
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
import scala.io._ import java.util.regex._ class ExtendedString(self:String) { def gsub(reg:String)(f:(String)=>String) = { val result = new StringBuffer val m = Pattern.compile("\\d+").matcher(self) while(m.find) m.appendReplacement(result, f(m.group)) m.appendTail(result) result.toString } def taxed():String = { gsub("\\d+"){x => (Integer.parseInt(x)*1.05).asInstanceOf[Int].toString} } } implicit def string2ext(self:String) = new ExtendedString(self) "ダイコン150円、ハクサイ120円、ジャガイモ30円".taxed
Rating0/0=0.00-0+
[ reply ]
yuin
#861()
[
Scala
]
Rating0/0=0.00
import scala.io._ import java.util.regex._ class ExtendedString(self:String) { def gsub(reg:String)(f:(String)=>String) = { val result = new StringBuffer val m = Pattern.compile("\\d+").matcher(self) while(m.find) m.appendReplacement(result, f(m.group)) m.appendTail(result) result.toString } def taxed():String = { gsub("\\d+"){x => (Integer.parseInt(x)*1.05).asInstanceOf[Int].toString} } } implicit def string2ext(self:String) = new ExtendedString(self) "ダイコン150円、ハクサイ120円、ジャガイモ30円".taxedRating0/0=0.00-0+
[ reply ]