■ 전각 문자에서 반각 문자를 구하는 방법을 보여준다.
▶ 예제 코드 (PY)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
def getHalfWidthCharacter(fullWidthCharacter): characterOffsetString = "0xfee0" blankFullWidthCharacterString = "0x3000" characterOffsetASCIIHexadecimal = int(characterOffsetString, 16) blankFullWidthCharacterASCIIHexadecimal = int(blankFullWidthCharacterString, 16) blankFullWidthCharacterHexadecimal = hex(blankFullWidthCharacterASCIIHexadecimal) fullWidthCharacterASCIIHexadecimal = ord(fullWidthCharacter) fullWidthCharacterHexadecimal = hex(fullWidthCharacterASCIIHexadecimal) if fullWidthCharacterASCIIHexadecimal >= characterOffsetASCIIHexadecimal: halfWidthCharacter = fullWidthCharacterASCIIHexadecimal - characterOffsetASCIIHexadecimal elif fullWidthCharacterASCIIHexadecimal == blankFullWidthCharacterASCIIHexadecimal: halfWidthCharacter = blankFullWidthCharacterHexadecimal return chr(halfWidthCharacter) print(getHalfWidthCharacter("!")) print(getHalfWidthCharacter("+")) print(getHalfWidthCharacter("<")) print(getHalfWidthCharacter("?")) """ ! + < ? """ |