2
1

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.

【Coldfusion】文字列の全角・半角を妥当な形に変換する

Last updated at Posted at 2015-11-06
ZenkakuHankakuTest.cfm
<cfset zen1 = "Zenkaku" />
<cfset zen2 = "ゼンカク" />
<cfset zen3 = "2015/12/31 23:59@" />
<cfset han1 = "Hankaku" />
<cfset han2 = "ハンガク" />
<cfset han3 = "2015/12/31 23:59@" />

<cfset aNormalizer = createObject("java", "java.text.Normalizer") />

<cfoutput>
zen1を変換:#aNormalizer.normalize(zen1, createObject("java", "java.text.Normalizer$Form").valueOf("NFKC"))#<br />
zen2を変換:#aNormalizer.normalize(zen2, createObject("java", "java.text.Normalizer$Form").valueOf("NFKC"))#<br />
zen3を変換:#aNormalizer.normalize(zen3, createObject("java", "java.text.Normalizer$Form").valueOf("NFKC"))#<br />
han1を変換:#aNormalizer.normalize(han1, createObject("java", "java.text.Normalizer$Form").valueOf("NFKC"))#<br />
han2を変換:#aNormalizer.normalize(han2, createObject("java", "java.text.Normalizer$Form").valueOf("NFKC"))#<br />
han3を変換:#aNormalizer.normalize(han3, createObject("java", "java.text.Normalizer$Form").valueOf("NFKC"))#<br />
</cfoutput>

結果

zen1を変換:Zenkaku
zen2を変換:ゼンカク
zen3を変換:2015/12/31 23:59@
han1を変換:Hankaku
han2を変換:ハンガク
han3を変換:2015/12/31 23:59@

java.text.Normalizerを都合2回Createしなければいけないのが気付きづらい。

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?