我有以下代码,我想要一条 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/