Class StringUtils

java.lang.Object
com.sap.cloud.sdk.cloudplatform.util.StringUtils

@Beta public class StringUtils extends Object
Internal utility class for common String operations.
Since:
5.21.0
  • Constructor Details

    • StringUtils

      public StringUtils()
  • Method Details

    • startsWithIgnoreCase

      public static boolean startsWithIgnoreCase(@Nullable String str, @Nullable String prefix)
      Checks if the given string starts with the specified prefix, ignoring case.
      Parameters:
      str - the string to check
      prefix - the prefix to look for
      Returns:
      true if the string starts with the prefix, ignoring case; false otherwise
    • endsWithIgnoreCase

      public static boolean endsWithIgnoreCase(@Nullable String str, @Nullable String suffix)
      Checks if the given string ends with the specified suffix, ignoring case.
      Parameters:
      str - the string to check
      suffix - the suffix to look for
      Returns:
      true if the string ends with the suffix, ignoring case; false otherwise
    • removeStartIgnoreCase

      @Nullable public static String removeStartIgnoreCase(@Nullable String s, @Nullable String prefix)
      Removes the specified prefix from the start of the string, ignoring case.
      Parameters:
      s - the string to modify
      prefix - the prefix to remove
      Returns:
      the modified string with the prefix removed, or the original string if it did not start with the prefix;
    • removeEndIgnoreCase

      @Nonnull public static String removeEndIgnoreCase(@Nonnull String s, @Nonnull String prefix)
      Removes the specified suffix from the end of the string, ignoring case.
      Parameters:
      s - the string to modify
      prefix - the suffix to remove
      Returns:
      the modified string with the suffix removed, or the original string if it did not end with the suffix;
    • isBlank

      public static boolean isBlank(@Nullable String s)
      Checks if the given string is blank.
      Parameters:
      s - the string to check
      Returns:
      true if the string is null, empty, or contains only whitespace characters; false otherwise
    • isEmpty

      public static boolean isEmpty(@Nullable String s)
      Checks if the given string is empty.
      Parameters:
      s - the string to check
      Returns:
      true if the string is null, or empty (""); false otherwise
    • isBlank

      public static boolean isBlank(@Nullable CharSequence s)
      Checks if the given CharSequence is blank or empty.
      Parameters:
      s - the CharSequence to check
      Returns:
      true if the CharSequence is null, empty, or contains only whitespace characters; false otherwise
    • capitalize

      @Nullable public static String capitalize(@Nullable String s)
      Capitalizes the first character of the given string.
      Parameters:
      s - the string to capitalize
      Returns:
      the string with the first character capitalized, or null if the input is null or empty
    • uncapitalize

      @Nonnull public static String uncapitalize(@Nonnull String s)
      Uncapitalizes the first character of the given string.
      Parameters:
      s - the string to uncapitalize
      Returns:
      the string with the first character uncapitalized, or null if the input is null or empty
    • trimToNull

      @Nullable public static String trimToNull(@Nullable String s)
      Trims the given string and returns null if the result is empty.
      Parameters:
      s - the string to trim
      Returns:
      the trimmed string, or null if the input is null or empty after trimming
    • prependIfMissing

      @Nonnull public static String prependIfMissing(@Nonnull String s, @Nonnull String prefix)
      Prepends the specified prefix to the string if it does not already start with that prefix, ignoring case.
      Parameters:
      s - the string to modify
      prefix - the prefix to prepend
      Returns:
      the modified string with the prefix prepended if it was not already present; otherwise, the original string
    • substringBefore

      @Nullable public static String substringBefore(@Nullable String string, char suffix)
      Returns the substring of the given string before the first occurrence of the specified suffix character.
      Parameters:
      string - the string to search
      suffix - the character to search for
      Returns:
      the substring before the first occurrence of the suffix character, or the original string if the suffix is not found;