as title states, how 1 concatenate 2 attributed strings?
the attributedstrings not contain concat method, , of course short-cut of concat ( + operator on strings) not work either.
using ctrl+f search "concat" on attributedstring javadocs... javadocs don't mention concat, nor appear mention means combine 2 attributed strings (https://docs.oracle.com/javase/7/docs/api/java/text/attributedstring.html).
specifics on end desire:
let's have 2 objects each 2 strings. (following json format)
{ "term" : "1s", "superscript" : "1" }, { "term" : "1s", "superscript" : "2" }
what need combine of these terms , superscripts in following, ordered format:
term+superscript+term+superscript
however, superscripts must super scripts (hence use of attributedstrings).
sorry far know, there no easy way it. can following:
attributedcharacteriterator aci1 = attributedstring1.getiterator(); attributedcharacteriterator aci2 = attributedstring2.getiterator(); stringbuilder sb = new stringbuilder(); char ch = aci1.current(); while( ch != characteriterator.done) { sb.append( ch); ch = aci1.next(); } ch = aci2.current(); while( ch != characteriterator.done) { sb.append( ch); ch = aci2.next(); } attributedstring combined = new attributedstring( sb.tostring()); combined.addattributes( aci1.getattributes(), 0, aci1.getendindex()); combined.addattributes( aci2.getattributes(), aci1.getendindex(), aci1.getendindex() + aci2.getendindex());
Comments
Post a Comment