3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

全角文字を半角文字に変換する

Posted at

全角文字を使いこなす人頭良すぎる。
どうやって入力しているのか想像できない。

function zen2han(byval text)
    dim i, buf, ch
    i = 1
    buf = ""
    do while i <= len(text)
        ch = mid(text, i, 1)
        select case ch
        case "/" ch = "/" ' 意図的に使用される全角文字
        case "." ch = "." ' 半角記号に見えて実は全角というパターン
        case "," ch = "," ' 半角記号に見えて実は全角というパターン
        case "-" ch = "-" ' 半角記号に見えて実は全角というパターン
        case "―" ch = "-" ' 半角記号に見えて実は全角というパターン
        case "‐" ch = "-" ' 半角記号に見えて実は全角というパターン
        case "♯" ch = "#" ' 信じられないことに音楽記号を使ってくる人が居ます
        case " " ch = " "
        case "!" ch = "!"
        case "”" ch = """"
        case "#" ch = "#"
        case "$" ch = "$"
        case "%" ch = "%"
        case "&" ch = "&"
        case "’" ch = "'"
        case "(" ch = "("
        case ")" ch = ")"
        case "=" ch = "="
        case "ー" ch = "-"
        case "~" ch = "~"
        case "^" ch = "^"
        case "|" ch = "|"
        case "¥" ch = "\"
        case "「" ch = "["
        case "」" ch = "]"
        case "{" ch = "{"
        case "}" ch = "}"
        case "`" ch = "`"
        case "@" ch = "@"
        case "*" ch = "*"
        case ":" ch = ":"
        case ";" ch = ";"
        case "+" ch = "+"
        case "<" ch = "<"
        case ">" ch = ">"
        case "、" ch = ","
        case "。" ch = "."
        case "?" ch = "?"
        case "・" ch = "/"
        case "_" ch = "_"
        case "1" ch = "1"
        case "2" ch = "2"
        case "3" ch = "3"
        case "4" ch = "4"
        case "5" ch = "5"
        case "6" ch = "6"
        case "7" ch = "7"
        case "8" ch = "8"
        case "9" ch = "9"
        case "0" ch = "0"
        case "a" ch = "a"
        case "b" ch = "b"
        case "c" ch = "c"
        case "d" ch = "d"
        case "e" ch = "e"
        case "f" ch = "f"
        case "g" ch = "g"
        case "h" ch = "h"
        case "i" ch = "i"
        case "j" ch = "j"
        case "k" ch = "k"
        case "l" ch = "l"
        case "m" ch = "m"
        case "n" ch = "n"
        case "o" ch = "o"
        case "p" ch = "p"
        case "q" ch = "q"
        case "r" ch = "r"
        case "s" ch = "s"
        case "t" ch = "t"
        case "u" ch = "u"
        case "v" ch = "v"
        case "w" ch = "w"
        case "x" ch = "x"
        case "y" ch = "y"
        case "z" ch = "z"
        case "A" ch = "A"
        case "B" ch = "B"
        case "C" ch = "C"
        case "D" ch = "D"
        case "E" ch = "E"
        case "F" ch = "F"
        case "G" ch = "G"
        case "H" ch = "H"
        case "I" ch = "I"
        case "J" ch = "J"
        case "K" ch = "K"
        case "L" ch = "L"
        case "M" ch = "M"
        case "N" ch = "N"
        case "O" ch = "O"
        case "P" ch = "P"
        case "Q" ch = "Q"
        case "R" ch = "R"
        case "S" ch = "S"
        case "T" ch = "T"
        case "U" ch = "U"
        case "V" ch = "V"
        case "W" ch = "W"
        case "X" ch = "X"
        case "Y" ch = "Y"
        case "Z" ch = "Z"
        end select
        buf = buf & ch
        i = i + 1
    loop
    zen2han = buf
end function
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?