Skip to content

Instantly share code, notes, and snippets.

@ekd123
Created August 28, 2013 07:12
Show Gist options
  • Select an option

  • Save ekd123/6362987 to your computer and use it in GitHub Desktop.

Select an option

Save ekd123/6362987 to your computer and use it in GitHub Desktop.

Revisions

  1. ekd123 created this gist Aug 28, 2013.
    39 changes: 39 additions & 0 deletions 提取文本中的漢字.tcl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    #!/usr/bin/env tclsh

    package require Tk
    pack [ttk::label .l1 -text "在下面的框中輸入要檢查的文本"] -fill x
    pack [text .input] -fill both -expand 1
    pack [ttk::label .l2 -text "結果"] -fill x
    pack [text .output] -fill both -expand 1
    pack [ttk::button .start -text "開始" -command startFind] -side right

    proc charIsChinese {ch} {
    set code [scan $ch %c]
    if { $code > 0x3400 && $code < 0x4DB5 } {
    return true
    } elseif { $code > 0x4E00 && $code < 0x9FA5 } {
    return true
    } elseif { $code > 0x9FA6 && $code < 0x9FBB } {
    return true
    } elseif { $code > 0xF900 && $code < 0xFA2D } {
    return true
    } elseif { $code > 0xFA30 && $code < 0xFA6A } {
    return true
    } elseif { $code > 0xFA70 && $code < 0xFAD9 } {
    return true
    } elseif { $code > 0x20000 && $code < 0x2A6D6 } {
    return true
    } elseif { $code > 0x2F800 && $code < 0x2FA1D } {
    return true
    } else {
    return false
    }
    }

    proc startFind {} {
    foreach ch [split [.input get 1.0 {end -1c}] {}] {
    if { [charIsChinese $ch] } {
    .output insert end $ch
    }
    }
    }