我正在这样做:
int level = ...;//some value from game
Analytics.newDesignEvent(String.format("level_end:%02d:win", level));
我发现有些设备发送带有 unicode 符号的字符串,例如“٠١”:
level_end:٠١:win
我尝试在我的环境中重现它,但是 String.format 对于任何整数值都可以正常工作。 这可能是由特定区域设置造成的吗?否则为什么会发生这种情况?
更新2: 我没有找到任何关于 string + int/float/etc 的信息。连接也考虑区域设置。 smbd 知道吗?
最佳答案
在java文档中说:
Number localization. Some conversions use localized decimal digits rather than the usual ASCII digits. So formatting 123 with %d will give 123 in English locales but ١٢٣ in appropriate Arabic locales, for example. This number localization occurs for the decimal integer conversion %d, the floating point conversions %e, %f, and %g, and all date/time %t or %T conversions, but no other conversions.
顺便说一句,٠١ 的意思是阿拉伯数字 01。所以我将把我的电话替换为
String.format(Locale.US, "level_end:%02d:win", level)
看看它是否有帮助。
关于java String.Format ("%02d")产生奇怪的 unicode 字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28386257/