Class OpenTruncate

java.lang.Object
cloud.opencode.base.string.text.OpenTruncate

public final class OpenTruncate extends Object
String Truncate Utility - Provides string truncation methods. 字符串截断工具 - 提供字符串截断方法。

Features | 主要功能:

  • Head truncation with ellipsis - 头部截断带省略号
  • Middle truncation - 中间截断
  • Byte-based truncation for multi-byte strings - 基于字节的截断

Usage Examples | 使用示例:

String t = OpenTruncate.truncate("Hello World", 8); // "Hello..."
String m = OpenTruncate.truncateMiddle("abcdefghij", 7); // "ab...ij"

Security | 安全性:

  • Thread-safe: Yes (stateless utility) - 线程安全: 是(无状态工具类)
  • Null-safe: Yes - 空值安全: 是
Since:
JDK 25, opencode-base-string V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • truncate

      public static String truncate(String str, int maxLength)
    • truncate

      public static String truncate(String str, int maxLength, String ellipsis)
    • truncateMiddle

      public static String truncateMiddle(String str, int maxLength)
    • truncateMiddle

      public static String truncateMiddle(String str, int maxLength, String ellipsis)
    • truncateByBytes

      public static String truncateByBytes(String str, int maxBytes, String charset)