我有一個由6個字母組成的字符串,例如:「abcdef」。 我需要添加「。」每兩個字符,所以它會是這樣的:「ab.cd.ef」。 我在java中工作,我嘗試這樣做:如何將字符添加到特定索引中的字符串?
private String FormatAddress(String sourceAddress) {
char[] sourceAddressFormatted = new char[8];
sourceAddress.getChars(0, 1, sourceAddressFormatted, 0);
sourceAddress += ".";
sourceAddress.getChars(2, 3, sourceAddressFormatted, 3);
sourceAddress += ".";
sourceAddress.getChars(4, 5, sourceAddressFormatted, 6);
String s = new String(sourceAddressFormatted);
return s;
}
但是我收到奇怪的值,比如[C @ 2723b6。
感謝提前:)
爲了儘快提供更好的幫助,請發佈[SSCCE](http://sscce.org/)。 – 2013-05-03 08:37:27