@Test public void removeTags() { assertEquals("Test", Text.removeTags("<col=FFFFFF>Test</col>")); assertEquals("Test", Text.removeTags("<img=1><s>Test</s>")); assertEquals("Zezima (level-126)", Text.removeTags("<col=ffffff><img=2>Zezima<col=00ffff> (level-126)")); assertEquals("", Text.removeTags("<colrandomtext test>")); assertEquals("Not so much.", Text.removeTags("<col=FFFFFF This is a very special message.</col>Not so much.")); assertEquals("Remove no tags", Text.removeTags("Remove no tags")); }
public static String removeTags(String str) { StringBuilder builder = new StringBuilder(str.length()); boolean inTag = false; for (int i = 0; i < str.length(); i++) { char currentChar = str.charAt(i); if (currentChar == '<') { inTag = true; } else if (currentChar == '>') { inTag = false; } else if (!inTag) { builder.append(currentChar); } } return builder.toString(); }
Text { public static String removeTags(String str) { StringBuilder builder = new StringBuilder(str.length()); boolean inTag = false; for (int i = 0; i < str.length(); i++) { char currentChar = str.charAt(i); if (currentChar == '<') { inTag = true; } else if (currentChar == '>') { inTag = false; } else if (!inTag) { builder.append(currentChar); } } return builder.toString(); } }
Text { public static String removeTags(String str) { StringBuilder builder = new StringBuilder(str.length()); boolean inTag = false; for (int i = 0; i < str.length(); i++) { char currentChar = str.charAt(i); if (currentChar == '<') { inTag = true; } else if (currentChar == '>') { inTag = false; } else if (!inTag) { builder.append(currentChar); } } return builder.toString(); }  }
Text { public static String removeTags(String str) { StringBuilder builder = new StringBuilder(str.length()); boolean inTag = false; for (int i = 0; i < str.length(); i++) { char currentChar = str.charAt(i); if (currentChar == '<') { inTag = true; } else if (currentChar == '>') { inTag = false; } else if (!inTag) { builder.append(currentChar); } } return builder.toString(); }  static String removeTags(String str); }
Text { public static String removeTags(String str) { StringBuilder builder = new StringBuilder(str.length()); boolean inTag = false; for (int i = 0; i < str.length(); i++) { char currentChar = str.charAt(i); if (currentChar == '<') { inTag = true; } else if (currentChar == '>') { inTag = false; } else if (!inTag) { builder.append(currentChar); } } return builder.toString(); }  static String removeTags(String str);  }