I would like to take all the spans of one type in a CharSequence and convert them to a different type. For example, convert all the bold spans to underline spans:
How would I do that?
(This was a problem I was facing today, and since I have solved it now, I am adding a Q&A pair here. My answer is below.)

How to change spans from one type to another
In order change the spans, you need to do the following things
getSpans()getSpanStart()andgetSpanEnd()removeSpan()setSpan()in the same locations as the old spansHere is the code to do that:
Notes
boldString.toString()when creating theSpannableString. You would use the originalboldStringto get the span ranges.See also