您可以将字符串存储在两个变量font_size
和html_template
和使用sprintf
功能“编译”的价值观模板你想如下:
char* html_template = "<font color='#00ff00' size='%d'> SampleText </font>";
int font_size = superFontSizeCalculation();
char* compiled_html = malloc(strlen(html_template));
sprintf(compiled_html, html_template, font_size);
我不检查的任何回报str *函数,但在实际使用中,您应该这样做。
编辑:正如你改变主意,想知道java和不C,你可以通过将标签模板串有一个小模板引擎相同的机制,并通过自己的价值观更换标签编译。
例如:
static final String FONT_SIZE_TAG = "<FONT_SIZE_TAG>";
static final String FONT_COLOR_TAG = "<FONT_COLOR_TAG>";
String htmlString ="<font color='" + FONT_COLOR_TAG + "' size='" + FONT_SIZE_TAG + "'> SampleText </font>";
String compiled = htmlString.replace(FONT_COLOR_TAG, "#00ff00").replace(FONT_SIZE_TAG, String.valueOf(FONT_COLOR_TAG));
为什么Ç标签?仅仅因为* string *这个词? – haccks
请更清楚地解释你的问题。你想解析字体的原始字符串并将它除以4吗?你试过什么了? – bknopper
您使用Java还是C?你有两个标签,但我肯定不是这种情况... –