Here you can find the source of truncate(String message, String substring)
Parameter | Description |
---|---|
message | An error message or other string that needs to be truncated. |
substring | A substring to find in message . |
public static String truncate(String message, String substring)
//package com.java2s; public class Main { /**//ww w . j a va 2s.com * This method is typically used to remove system-specific text from * error messages, so that the error messages can be checked in a * system-independent fashion. * @param message An error message or other string that * needs to be truncated. * @param substring A substring to find in {@code message}. * @return If {@code message} contains * {@code substring} then the return value * consists of the portion of {@code message} * up to and including {@code substring}, * followed by "...". Otherwise the return * value is {@code message}. */ public static String truncate(String message, String substring) { int i = message.indexOf(substring); if (i < 0) { return message; } return message.substring(0, i + substring.length()) + "..."; } }