将数值添加到字符串名称的最简单方法
我有一个名为“name”的字符串名称,我希望将其转换为 name1、name2、name3、name4
执行此操作的最佳方法是什么?有没有办法把它绑成一个循环?
public String name;
循环开始
public void onClick(DialogInterface dialog, int whichButton) {
name = input.getText().toString();
// Do something with value!
}
循环结束
寻找每次经过循环变成 name1, name2, name3, name4 ..
是否可以做类似的事情,
name(nameLoop) = input.getText().toString();
...
nameLoop++;
我希望这不会太令人困惑。
提前致谢!
I have a string name called "name" that I am looking to convert to name1, name2, name3, name4
what would be the best way to go about doing this? Is there a way to tie it into a loop?
public String name;
Loop Start
public void onClick(DialogInterface dialog, int whichButton) {
name = input.getText().toString();
// Do something with value!
}
Loop End
Looking for each time it goes through the loop to become name1, name2, name3, name4..
is it possible to do something like
name(nameLoop) = input.getText().toString();
...
nameLoop++;
I hope this isnt too confusing.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请编写类似
String newName = name+nameLoop;
或String newName = "name"+nameLoop;
的内容。当然,如果您确实希望它们是 name1、name2 等,
Sure, write something like
String newName = name+nameLoop;
or
String newName = "name"+nameLoop;
if you literally want them to be name1, name2 etc.