6
6

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.

地番の本番が4桁、枝番が3桁になるようにゼロパディング(ゼロ埋め)する

Posted at

ソースはGithubで管理しています

下記のような変換をするスクリプトです。

100-1 → 0100-001
200  → 0200-000
Chiban-Zero-Padding.ps1
function Zero-Padding() {
   $str = [String]$ARGS[0]
   $length = $ARGS[1]

   While ( $str.Length -lt $length ) {
      $str = "0$str"
   }
   Return $str
}

$chiban = [String]$ARGS[0] -Split("-")

$oya = Zero-Padding $chiban[0] 4
if ( $chiban.Length -eq 2 ) {
   $eda = Zero-Padding $chiban[1] 3
} else {
   $eda = "000"
}

$chiban = "$oya-$eda"

Write-Output $chiban

Docuworks Deskではファイル名が、Excelでは地番名が、それぞれ地番が文字列として認識されて地番順に並べ替えることができないので地番をゼロ埋めしてちゃんと並ぶように変換します。

枝番の無い地番に無理矢理「-000」を追加しているのは、隣接の道路に表示が起こされている土地の中に「920番」と「920番2」があって、それぞれ「0920」、「0920-002」とすると、「0920」より先に「0920-002」が表示されてしまうためです。

逆変換のゼロサプレスもあった方が便利かもしれませんね。

6
6
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
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?