简体   繁体   中英

How to Insert slashes into a string?

I have a birth date number in the format: 890520, so yy/mm/dd. However, I need to display it separated by slashes, eg. 89/05/20

How can I do this, as there is no delimiter with which I can split the string?

String a = "890520";
System.out.println(a.substring(0, 2) + "/" + a.substring(2, 4) + "/" + a.substring(4));

substring() is what you are looking for.

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