我是来自python的java的新手.我想知道如何在java中乘以一个字符串.在python我会这样做:
str1 = "hello"
str2 = str1 * 10
Run Code Online (Sandbox Code Playgroud)
字符串2现在具有以下值:
#str2 == 'hellohellohellohellohellohellohellohellohellohello'
Run Code Online (Sandbox Code Playgroud)
我想知道在java中实现这个最简单的方法是什么.我是否必须使用for循环或是否有内置方法?
编辑1
感谢您的回复我已经找到了解决问题的优雅方案:
str2 = new String(new char[10]).replace("\0", "hello");
Run Code Online (Sandbox Code Playgroud)
注意:这个答案最初由user102008发布:https://stackoverflow.com/a/4903603
我正在使用App引擎,我正在尝试从请求中获取时区.但是,当在本地主机上时,似乎总是将"ZZ"作为国家代码返回,而该国家代码不是pytz库中的国家/地区.
这段代码:
country = self.request.headers['X-Appengine-Country']
logging.info(country)
tz = pytz.country_timezones(country)
Run Code Online (Sandbox Code Playgroud)
产生此错误:
return self.data[key.upper()]
KeyError: 'ZZ'
Run Code Online (Sandbox Code Playgroud)
非常感谢您的帮助
我试图通过谷歌应用程序引擎通道api从画布发送图像到另一个客户端,然后将显示相同的图像.正在接收消息但未显示图像.
在发送方:
var image = context.getImageData(0, 0, imageCanvas.width, imageCanvas.height);
var buffer = new ArrayBuffer(image.data.length);
var bytes = new Uint8Array(buffer);
for (var i=0; i<bytes.length; i++) {
bytes[i] = image.data[i];
}
sendMessage({image: buffer});
Run Code Online (Sandbox Code Playgroud)
在另一端渲染数据:
var bytes = new Uint8Array(buffer.size);
var image = context.createImageData(imageCanvas.width, imageCanvas.height);
for (var i=0; i<image.length; i++) {
image.data[i] = bytes[i];
}
context.drawImage(image, 0, 0);
Run Code Online (Sandbox Code Playgroud)
控制台一直说最后一行有一个Type错误.
javascript google-app-engine python-2.7 channel-api html5-canvas