2013-05-14 85 views
-2
Sentences : 
Test Your Skills 1, ... 2, ... 3, .... 
Specify Your Skills 1, ..2, ...3, .... 
Check Your Skills 1, ..2, ...3, .... 

..未知字符/字

restofsentence="Your Skills"+ ? ; 
String test = "Test" + restofsentence 
String specify = "Specify" + restofsentence 
String check = "Check" + restofsentence 

我如何定义restofsentence变量, “?”必须定义任意数量的

“测试=‘测试你的技能6’”,“测试=‘测试你的技能36’”都必须是对不使用循环,因为我们不知道最后一个数字

回答

1

可以使用String.format()方法。

String format = "%1$s your skill %2$d"; 
String test = String.format(format, "Test", 4); 
+0

谢谢,是否可以单独使用'字符串格式'?我的意思是'格式=指定你的技能12'也'格式=测试你的技能7' – santral 2013-05-14 16:56:55

+1

你可以组装任何类型的字符串,只要追加它们就像'test =“Test”+“你的技能”+ 7; – SimonSays 2013-05-14 17:00:54