基本的に私はこれをgroovyで設計および実装する必要があります。これは、特定の段落をエンコードおよびデコードすることですか?
1 に答える
0
あなたはこれをチェックすることができます
http://groovy.codehaus.org/ExpandoMetaClass+-+Dynamic+Method+Names
これは、コーデックの典型的な使用例を示しています。
基本的に(そのリンクから)のようなもの
class HTMLCodec {
static encode = { theTarget ->
HtmlUtils.htmlEscape(theTarget.toString())
}
static decode = { theTarget ->
HtmlUtils.htmlUnescape(theTarget.toString())
}
}
HtmlUtilsは使用しませんが、構造は同じです。
編集-これは、置換を行う方法の例です。これはおそらくもっとグルーヴィーで、句読点を処理しないことに注意してくださいが、役立つはずです
def plainText = 'hello'
def solutionChars = new char[plainText.size()]
for (def i = 0; i < plainText.size(); i++){
def currentChar = plainText.charAt(i)
if (Character.isUpperCase(currentChar))
solutionChars[i] = Character.toLowerCase(currentChar)
else
solutionChars[i] = Character.toUpperCase(currentChar)
}
def cipherText = new String(solutionChars)
println(solutionChars)
編集-これはもう少しグルーヴィーなソリューションです
def plainText = 'hello'
def cipherText = ""
plainText.each {c ->
if (Character.isUpperCase((Character)c))
cipherText += c.toLowerCase()
else
cipherText += c.toUpperCase()
}
println(cipherText)
于 2011-01-06T20:07:43.977 に答える