With older systems, payment processing may not be accepted if the name of the bank account uses a yoon or a sokuon.
The system (SQLserver) of the company I work for is exactly that, and in the case of manual input, it does not accept yoon and sokuon, but if it is copy and paste etc. it slips in and an error occurs when payment processing is applied. ... (depending on the bank) was not a little.
Also, as a future plan, I want to extract the data from the document (created in Excel) to be registered in the system and post it directly to SQL server with pyodbc
, so I do not correct the yoon / sokuon at that time at the latest. It was necessary to write such a code because it would follow the same rut as, and if I wrote it with an idea, it worked reasonably well.
That's why there may not be much demand, but I will make my debut on Qiita here!
code
you_soku = 'ァ ゥ ゥ ゥ ァ'
print('Change before-->', you_soku) #For confirmation
ys_dict = {'ァ': 'A', 'I': 'I', 'ゥ': 'C', 'E': 'E', 'Oh': 'O', '㽬': 'ヤ', 'Shu': 'Yu', 'YO': 'Yo', 'Tsu': 'Tsu'}
for ys in ys_dict.keys():
while ys in you_soku:
you_soku = you_soku.replace(ys, ys_dict[ys])
print('After change-->', you_soku) #For confirmation
Output result
Change before-->ァ ゥ ゥ ゥ ァ
After change-->Yayuyo
Loop the yoon / sokuon dictionary and replace the character (value) corresponding to the key as long as the key is in the target character string (in the above case, in the character string stored in you_soku
). There is.
As some of you may have noticed, if you change the variable of the nested target string (you_soku
in the above case), you will end up in an infinite loop. .. (Actually, it ’s the mouth I did w)
I will try it under the name of an account that is likely to actually exist. Of course, he is a fictional person. (It's a light name like a rock musician, but I'm not a fan.)
code
account_name = 'Kikkawa Shoji'
print('Change before-->', account_name) #For confirmation
ys_dict = {'ァ': 'A', 'I': 'I', 'ゥ': 'C', 'E': 'E', 'Oh': 'O', '㽬': 'ヤ', 'Shu': 'Yu', 'YO': 'Yo', 'Tsu': 'Tsu'}
for ys in ys_dict.keys():
while ys in account_name:
account_name = account_name.replace(ys, ys_dict[ys])
print('After change-->', account_name) #For confirmation
Output result
Change before-->Kikkawa Shoji
After change-->Kiwashi
Normally, the system should handle it so that it is not necessary to use such code. Well, it doesn't start even if I say it, so I wrote it.
We welcome your suggestions and opinions. I'm still an apprentice, so I'd like you to put in a tsukkomi frankly.
Recommended Posts