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