简体   繁体   English

如何将字符串连接成数字,例如:我需要基于for循环的tkr1,tkr2…

[英]how to concatenate a string to a numeric,for eg:i need tkr1,tkr2… based on a for loop

string str1=tkr;
for(i=1;i<=10;i++)
{
string str2=str1+i;
sopln(str2);

}

I need result like this.. tkr1 tkr2 tkr3 tkr4 tkr5...could any one re-write the code which could give the proper output? 我需要这样的结果.. tkr1 tkr2 tkr3 tkr4 tkr5 ...任何人都可以重写代码以提供适当的输出吗?

Its not mentioned which language you are using so it would be not possible to give exact answer: 它没有提到您使用的是哪种语言,因此不可能给出确切的答案:

This should work in most of the languages : 这应该适用于大多数语言:

String str1=tkr;
String str2 = "";
for(i=1;i<=10;i++)
{
str2=str2 + str1+i + " ";
}
print(str2)

And use mutable strings if you are using java 如果您使用的是Java,请使用可变字符串

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM