LoginSignup
0
2

More than 3 years have passed since last update.

Python 文字列 特定文字を置換による削除

Posted at

背景

備忘録です。
文字列を扱うときに、いらない文字が含まれいると削除する必要がある。
調べても、あんまりしっくりいくものがなかったので。
そこで、特定文字を無くなるように文字列置換をしてあげることで楽に処理できる。

change_and_remove_string.py
#邪魔な文字@,%を""に置換 
#:を.(コンマ)に置換
str_ = "@14@:@30@@%%%"
str_ = str_.replace('@', '')
str_ = str_.replace('%', '')
str_ = str_.replace(':', '.')
print("str_", str_)
#str_ 14.30

STR_ = "@14@:@30@@%%%"
STR_ = STR_.replace('@', '').replace('%', '').replace(':', '.')
print("STR_", STR_)
#STR_ 14.30
0
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2