Python/サンプル/文字列の置換・replace
の編集
Top
/
Python
/
サンプル
/
文字列の置換・replace
[
トップ
] [
編集
|
差分
|
バックアップ
|
添付
|
リロード
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
-- 雛形とするページ --
(no template pages)
#navi(../) * Pythonによる文字列置換・replace [#x8ffb046] 本資料は文字列の置換方法のサンプルコードを公開しています。 #contents #htmlinsertpcsp(ll-top.html,ll-sp.html) * 関連記事 [#ob62c74b] -[[Pythonで文字列置換・replace>Python/サンプル/文字列の置換・replace]] -[[Pythonで数値を文字列に変換する・str>Python/サンプル/数値を文字列に変換する・str]] -[[Pythonで指定した文字で分割し配列(list)に格納する方法・split>Python/サンプル/指定した文字で分割し配列(list)に格納する方法・split]] -[[Pythonで左右のスペース削除・strip, lstrip, rstrip>Python/サンプル/左右のスペース削除・strip, lstrip, rstrip]] -[[Pythonでリストに格納されている要素に区切り文字を指定し出力する・join>Python/サンプル/リストに格納されている要素に区切り文字を指定し出力する・join]] -[[Pythonで文字列の半角英字の大文字小文字化方法・upper,lower>Python/サンプル/半角英字の大文字小文字化方法・upper,lower]] -[[Pythonで文字列のleft,mid,rightを実現する方法>Python/サンプル/文字列のleft,mid,rightを実現する方法]] -[[Pythonで前方・後方文字列検索・find,rfind>Python/サンプル/前方・後方文字列検索・find,rfind]] -[[Pythonでカンマ区切りの文字列をリストに入れる方法・split>Python/サンプル/カンマ区切りの文字列をリストに入れる方法]] -[[Pythonでゼロパティングする方法・zfill>Python/サンプル/ゼロパティングする方法・zfill]] -[[Pythonで英字の大文字・小文字を区別せず比較する方法・re>Python/サンプル/英字の大文字・小文字を区別せず比較する方法・re]] * 文字列置換・replace [#r0ab021c] 以下にサンプルコードを記します。 str = "hello world hello world" print "Before: " + str print "After : " + str.replace("hello", "Hello") 構文は以下のようになります。 文字列.replace("置換前文字列", "置換後文字列") 上記サンプルコードを実行すると以下のようになります。 Before: hello world hello world After : Hello world Hello world helloが''H''elloに置換されているのが確認できます。 以上、Pythonによる文字列置換方法でした。 #htmlinsertpcsp(ll-btm.html,ll-sp.html)
タイムスタンプを変更しない
#navi(../) * Pythonによる文字列置換・replace [#x8ffb046] 本資料は文字列の置換方法のサンプルコードを公開しています。 #contents #htmlinsertpcsp(ll-top.html,ll-sp.html) * 関連記事 [#ob62c74b] -[[Pythonで文字列置換・replace>Python/サンプル/文字列の置換・replace]] -[[Pythonで数値を文字列に変換する・str>Python/サンプル/数値を文字列に変換する・str]] -[[Pythonで指定した文字で分割し配列(list)に格納する方法・split>Python/サンプル/指定した文字で分割し配列(list)に格納する方法・split]] -[[Pythonで左右のスペース削除・strip, lstrip, rstrip>Python/サンプル/左右のスペース削除・strip, lstrip, rstrip]] -[[Pythonでリストに格納されている要素に区切り文字を指定し出力する・join>Python/サンプル/リストに格納されている要素に区切り文字を指定し出力する・join]] -[[Pythonで文字列の半角英字の大文字小文字化方法・upper,lower>Python/サンプル/半角英字の大文字小文字化方法・upper,lower]] -[[Pythonで文字列のleft,mid,rightを実現する方法>Python/サンプル/文字列のleft,mid,rightを実現する方法]] -[[Pythonで前方・後方文字列検索・find,rfind>Python/サンプル/前方・後方文字列検索・find,rfind]] -[[Pythonでカンマ区切りの文字列をリストに入れる方法・split>Python/サンプル/カンマ区切りの文字列をリストに入れる方法]] -[[Pythonでゼロパティングする方法・zfill>Python/サンプル/ゼロパティングする方法・zfill]] -[[Pythonで英字の大文字・小文字を区別せず比較する方法・re>Python/サンプル/英字の大文字・小文字を区別せず比較する方法・re]] * 文字列置換・replace [#r0ab021c] 以下にサンプルコードを記します。 str = "hello world hello world" print "Before: " + str print "After : " + str.replace("hello", "Hello") 構文は以下のようになります。 文字列.replace("置換前文字列", "置換後文字列") 上記サンプルコードを実行すると以下のようになります。 Before: hello world hello world After : Hello world Hello world helloが''H''elloに置換されているのが確認できます。 以上、Pythonによる文字列置換方法でした。 #htmlinsertpcsp(ll-btm.html,ll-sp.html)
テキスト整形のルールを表示する