Java tutorial
//package com.java2s; public class Main { /** * Sets or removes the given key from the specified style and returns the * new style. If value is null then the flag is toggled. * * @param style * String of the form stylename[;key=value]. * @param key * Key of the style to be changed. * @param flag * Integer for the bit to be changed. * @param value * Optional boolean value for the given flag. */ public static String setStyleFlag(String style, String key, int flag, Boolean value) { if (style == null || style.length() == 0) { if (value == null || value.booleanValue()) { style = key + "=" + flag; } else { style = key + "=0"; } } else { int index = style.indexOf(key + "="); if (index < 0) { String sep = (style.endsWith(";")) ? "" : ";"; if (value == null || value.booleanValue()) { style = style + sep + key + "=" + flag; } else { style = style + sep + key + "=0"; } } else { int cont = style.indexOf(";", index); String tmp = ""; int result = 0; if (cont < 0) { tmp = style.substring(index + key.length() + 1); } else { tmp = style.substring(index + key.length() + 1, cont); } if (value == null) { result = Integer.parseInt(tmp) ^ flag; } else if (value.booleanValue()) { result = Integer.parseInt(tmp) | flag; } else { result = Integer.parseInt(tmp) & ~flag; } style = style.substring(0, index) + key + "=" + result + ((cont >= 0) ? style.substring(cont) : ""); } } return style; } }