8.77. right 末尾切り出し¶
書式1: right(str,長さ)
書式2: rightw(str,長さ)
文字列 \(str\) について末尾から長さパラメータで指定した文字数を切り出す。 マルチバイト文字を含む場合はrightwを使うこと。
利用例¶
importと入力データ(CSV)の準備
1import nysol.mcmd as nm 2 3with open('dat1.csv','w') as f: 4 f.write( 5'''id,str 61,abcdefg 72,12345678 83, 94,12 10''') 11 12with open('dat2.csv','w') as f: 13 f.write( 14'''id,str 151,あいうえお 162,1234567あ8 173,1あ 184,ああ 19''')
基本例
str項目の末尾から3文字を切り出す。
1nm.mcal(c='right($s{str},3)', a='rsl', i="dat1.csv", o="rsl1.csv").run() 2### rsl1.csv の内容 3# id,str,rsl 4# 1,abcdefg,efg 5# 2,12345678,678 6# 3,, 7# 4,12,12
マルチバイト文字を含む例
マルチバイト文字を含む場合はrightwを使う。
1nm.mcal(c='rightw($s{str},3)', a='rsl', i="dat2.csv", o="rsl2.csv").run() 2### rsl2.csv の内容 3# id,str,rsl 4# 1,あいうえお,うえお 5# 2,1234567あ8,7あ8 6# 3,1あ,1あ 7# 4,ああ,ああ