如何使用java从单词中提取大写字母?
example:
enter your words:Hello I Am Heyman
output:HIAH
Run Code Online (Sandbox Code Playgroud)
谢谢
你可以尝试replaceAll
String text2 = text.replaceAll("[^A-Z]", "");
Run Code Online (Sandbox Code Playgroud)
作为@Vic评论,包括所有英文/非英文大写字母.
String text2 = text.replaceAll("[^\p{Lu}]", "");
Run Code Online (Sandbox Code Playgroud)