简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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