• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javaandroidc++linuxc#objective-ccocoa誰得qtrubybathyscaphegamephpguicwindows翻訳pythonomegattwitterframeworkbtronarduinovb.net計画中(planning stage)directxpreviewertestゲームエンジンdom

漢数字を数字に数字を漢字に変換するライブラリ


コミットメタ情報

リビジョン97bf14a51c223a08dcaa7726773b7b22971fc027 (tree)
日時2015-04-04 15:32:06
作者bellyoshi <tccwas@gmai...>
コミッターbellyoshi

ログメッセージ

本体

変更サマリ

差分

--- /dev/null
+++ b/KansuuLib/KansuuLib/KansuuConverter.vb
@@ -0,0 +1,72 @@
1+Public Class KansuuConverter
2+
3+
4+
5+ Public Function GetKanji(ByVal number As Decimal) As String
6+ If 0 <= number AndAlso number <= 9 Then
7+ Return GetKanjiUnder9(number)
8+ End If
9+ If number <= 9999 Then
10+ Return GetKanjiUnder9999(number)
11+ End If
12+ Return GetKanjiUnderMuryouTaisu(number)
13+ End Function
14+
15+ Public Function GetKanjiUnderMuryouTaisu(ByVal number As Decimal) As String
16+ Dim _rankOfMultipleOfFourKanji() As String = {
17+ "", "万", "億", "兆", "京", "垓",
18+ "予", "穣", "溝", "潤", "正", "載", "極",
19+ "恒河沙", "阿僧祇", "那由多", "不可思議", "無量大数"}
20+ Dim nums(_rankOfMultipleOfFourKanji.Length - 1)
21+ Dim n As Decimal = number
22+ For i As Integer = 0 To nums.Length - 1
23+ nums(i) = n Mod 10000
24+ n = n \ 10000
25+ Next
26+ Dim numstr As String = String.Empty
27+ For i As Integer = nums.Length - 1 To 0 Step -1
28+ If nums(i) = 0 Then
29+ Continue For
30+ End If
31+ numstr += GetKanjiUnder9999(nums(i))
32+ numstr += _rankOfMultipleOfFourKanji(i)
33+ Next
34+ Return numstr
35+ End Function
36+
37+ Public Function GetKanjiUnder9999(ByVal number As Decimal) As String
38+ Dim _rankOfThreeKanji() As String = {"", "十", "百", "千"}
39+ Debug.Assert(0 <= number AndAlso number <= 9999)
40+ Dim nums(_rankOfThreeKanji.Length - 1) As Decimal
41+ Dim n As Decimal = number
42+ For i As Integer = 0 To nums.Length - 1
43+ nums(i) = n Mod 10
44+ n = n \ 10
45+ Next
46+ Dim numstr As String = String.Empty
47+ For i As Integer = nums.Length - 1 To 0 Step -1
48+ If nums(i) = 0 Then
49+ Continue For
50+ End If
51+ If i = 0 OrElse nums(i) <> 1 Then
52+ numstr += GetKanjiUnder9(nums(i))
53+ End If
54+ numstr += _rankOfThreeKanji(i)
55+ Next
56+ Return numstr
57+ End Function
58+
59+ Public Function GetKanjiUnder9(ByVal number As Decimal) As String
60+ Dim _ZeroToTenKanji() As String = {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九"}
61+ Debug.Assert(0 <= number AndAlso number <= 9)
62+ Return _ZeroToTenKanji(number)
63+ End Function
64+
65+ Private Sub New()
66+ End Sub
67+ Private Shared _instance As New KansuuConverter
68+ Public Shared Function GetInstance() As KansuuConverter
69+ Return _instance
70+ End Function
71+
72+End Class