2013-03-06 4 views
0

According to the documentation<object.property> 형식의 객체 속성을 참조 할 수 있습니다. 이 방법으로 String의 길이를 확인할 수 있었으면 좋겠지 만 작동하지 않는 것 같습니다. 나는이 방법이 String.length()이고 문서에 따르면 <mystr.length>과 같은 것을 수행하면 getLength()이라는 메서드와 length이라는 필드가 검색되지만 결코 length()이라는 메서드를 찾지는 않는다고 생각합니다. 나는 스칼라 REPL에서이 빠르게 검사 확인 :StringTemplate에서 String 값의 길이를 가져 오는 것

scala> import org.stringtemplate.v4._; import scala.collection.JavaConverters._; 
import org.stringtemplate.v4._ 
import scala.collection.JavaConverters._ 

scala> new ST("<xs:{ x | <x>:<x.length> }>").add("xs", List("hello", "goodbye").asJava).render 
res0: String = "hello: goodbye: " 

scala> case class S(val s:String) { def getLength = s.length } 
defined class S 

scala> new ST("<xs:{ x | <x>:<x.length> }>").add("xs", List("hello", "goodbye").map(S).asJava).render 
res1: String = "S(hello):5 S(goodbye):7 " 

문자열이 getLength() 방법 또는 작동 것 length 필드 ...

은 문자열의 길이를 얻을 수있는 쉬운 방법이 있나요했다 그렇다면? 어쩌면 내장 StringTemplate 함수 또는 내가 모르는 다른 방법일까요? strlen

scala> new ST("<xs:{ x | <x>:<strlen(x)> }>").add("xs", List("hello", "goodbye").asJava).render 
res6: String = "hello:5 goodbye:7 " 
:

답변