Search code examples
pythonpython-3.x

Python: Create strikethrough / strikeout / overstrike string type


I would appreciate some help in creating a function that iterates through a string and combines each character with a strikethrough character (\u0336). With the output being a striked out version of the original string. Like this..

Something like.

def strike(text):
    i = 0
    new_text = ''
    while i < len(text):
        new_text = new_text + (text[i] + u'\u0336')
        i = i + 1
    return(new_text)

So far I've only been able to concatenate rather than combine.


Solution

  • def strike(text):
        result = ''
        for c in text:
            result = result + c + '\u0336'
        return result
    

    Cool effect.