2016-03-05 32 views
-1

有沒有一種方法來轉換一個字符串(或爲CharSequence爲大寫的一部分?如何將String或CharSequence的一部分轉換爲大寫?

理想的情況下產生以下行爲的方法。

String hello = "hello"; 
System.out.println(hello.toUpperCase(0,3); 
//Output: HEL 

我知道toUpperCase(的),但我只想要大寫字符串的一部分。

+0

很簡單,自己編寫這樣的功能。 –

+0

看看'子串' – Reimeus

+0

只需要將substring()和'toUpperCase()' – schwobaseggl

回答

0

您可以用兩個調用做到這一點 - substring讓你感興趣的序列,然後toUpperCase以利用它:

System.out.println(hello.substring(0, 3).toUpperCase()); 
0

使用substring()得到字符串的一部分,然後改變它的情況下

String hello = "hello"; 
String temp = hello.subString(0,3).toUpperCase(); 
temp += hello.subString(3); 
System.out.println(temp); // HELlo 
相關問題