美文网首页
python(去掉字符串中不需要的字符)

python(去掉字符串中不需要的字符)

作者: OldSix1987 | 来源:发表于2016-09-03 18:16 被阅读632次

    案例


    (1)过滤掉用户输入中前后多余的空白字符:“    nick2008@gmail.com    ”
    (2)过滤掉某windows下编辑文本中的 “\r” :“hello world \r\n”
    (3)去掉文本中的unicode组合符号(音调):(nǐ)(hǎo)(mā)

    核心分析


    (1)str.strip(),str.lstrip(),str.rstrip()
    (2)切片+拼接
    (3)replace或正则的re.sub()
    (4)str.trasnslate()

    代码


    相关文章

      网友评论

          本文标题:python(去掉字符串中不需要的字符)

          本文链接:https://www.haomeiwen.com/subject/zaakettx.html