gpt4 book ai didi

java - 如何对 getString 单词进行空格?

转载 作者:行者123 更新时间:2023-12-01 20:15:42 25 4
gpt4 key购买 nike

我有以下代码,我想要一条 Toast 消息,内容是“恭喜 nameToasted,您获得了 5 分!”但我得到“CongratulationsnameToasted, you made5points!”。我已经尝试过 strings.xml 上的间距,但什么也没有。

String pointsInMessage = getString(R.string.congratulations) + nameToasted;
pointsInMessage = pointsInMessage + getString(R.string.you_made);
pointsInMessage = pointsInMessage + pointsPerAnswer;
pointsInMessage = pointsInMessage + getString(R.string.points_string) ;

最佳答案

尝试使用String.format(),如下所示:

final String pointsInMessage = String.format("%s %s, %s %d %s!", getString(R.string.congratulations), nameToasted, getString(R.string.you_made), pointsPerAnswer, getString(R.string.points_string));

假设pointsPerAnswer是一个整数。

关于java - 如何对 getString 单词进行空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45845207/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com