Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: 最多前 N 个字符 我需要将名为“TITLE”的变量“修剪”为仅 40 个字符
Java:限制/修剪/从字符串中删除多余的字符。我想在字符串变量的 40 个字符之后删除任何多余的字符。
String shortString = longString.substring(0, Math.min(longString.length(), 40));
您可能想仔细看看String类