Я хочу превратить строку в тег html с указанным шаблоном, например так:
Walking in the !boldstreet
Я хочу обнаружить !bold
в строке и превратить следующее слово в "<b>street</b>
".
String s = "Walking in the !boldstreet"
String result = null;
String[] styles = {"!bold", "!italic", "!deleted", "!marked"};
String[] tags = {"b", "i", "del", "mark"};
List<String> indexer = new ArrayList<String>(Arrays.asList(tags));
int index = 0;
for (String x: styles) {
if (s.startsWith(x)) {
result = style(s, indexer.get(index));
break;
}
index++;
}
if (result == null) result = s; //there was no formatting
return result;
//style method
public String style(String text, String tag) {
return "<" + tag + ">" + text + "</" + tag + ">";
}
Это работает, но когда я передаю ему что-то вроде этого:" Ходьба! Удалено в! Boldstreet "
только оно превратит! , Как я могу сделать так, чтобы все эти вещи превращались в html теги?