2013-05-14 76 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