replace all characters in a string with asterisks

后端 未结 4 662
旧巷少年郎
旧巷少年郎 2020-12-20 19:17

I have a string

name = \"Ben\"

that I turn into a list

word = list(name)

I want to replace the characters

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-20 19:32

    Probably you are looking for something like this?

    def blankout(instr, r='*', s=1, e=-1):
        if '@' in instr:
            # Handle E-Mail addresses
            a = instr.split('@')
            if e == 0:
                e = len(instr)
            return instr.replace(a[0][s:e], r * (len(a[0][s:e])))
        if e == 0:
            e = len(instr)
        return instr.replace(instr[s:e], r * len(instr[s:e]))
    

提交回复
热议问题