gpt4 book ai didi

Java 字符串转换(例如 hello world --> Hello World)

转载 作者:行者123 更新时间:2023-12-01 16:37:07 28 4
gpt4 key购买 nike

Possible Duplicate:
Capitalize First Char of Each Word in a String Java

编写进行以下字符串转换的函数的最简单方法是什么?以下是一些示例:

 - hello --> Hello
- hello world --> Hello World

我在数据库中只有一些标签,我想确保大小写一致;我当然知道这可以在传统意义上完成,但我只是想知道是否有更方便/可靠的功能可以帮助完成此任务。

最佳答案

您可以在 Apache Commons Lang 中使用 capitalizecapitalizeFullyWordUtils (org.apache.commons.lang)。

public static java.lang.String capitalize(java.lang.String str)

Capitalizes all the whitespace separated words in a String. Only the first letter of each word is changed. To convert the rest of each word to lowercase at the same time, use capitalizeFully(String).

public static java.lang.String capitalizeFully(java.lang.String str)

Converts all the whitespace separated words in a String into capitalized words, that is each word is made up of a titlecase character and then a series of lowercase characters.

关于Java 字符串转换(例如 hello world --> Hello World),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7879092/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com