Groovy等效于Java的String.format [英] Groovy equivalent of Java's String.format

查看:70
本文介绍了Groovy等效于Java的String.format的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的Java代码在Groovy中给出了错误.

The below Java code gives errors in Groovy..

  private String getSignature() {
    String timestamp = getUTCTimestamp();
    String nonce = getNonce();
    String digest = getPasswordDigest(nonce, timestamp);

    return String.format(
            "UsernameToken Username=\\"%s\\", PasswordDigest=\\"%s\\", Nonce=\\"%s\\", Created=\\"%s\\"", apiUsername, digest, nonce, timestamp);
}

特别是String.format行,如何在Groovy中重新编写?

Specifically the String.format line, how to re-write in Groovy?

推荐答案

应该能够做到

private String getSignature() {
    String timestamp = getUTCTimestamp();
    String nonce = getNonce();
    String digest = getPasswordDigest(nonce, timestamp);

    "UsernameToken Username=\"$apiUsername\", PasswordDigest=\"$digest\", Nonce=\"$nonce\", Created=\"$timestamp\""
}

这篇关于Groovy等效于Java的String.format的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆