Functions of Kaitei

$pathTop = [Environment]::GetFolderPath('Desktop')
cd "$pathTop\ps"
. .\Func_Files.ps1

function KaiteiName($nm){
    
    $Idx=$nm.IndexOf(".")
    if($Idx -gt 1){
        $nmEdit = MySubstring -strIn $nm -nCnt $Idx
        $Extent =  MySubstring -strIn $nm -nSta $Idx
    }else{
        $nmEdit=$nm
        $Extent=""
    }

    if($nmEdit -match "^\d{3}[A-D]\d{3}$"){return $nmEdit + "A" + $Extent}
    if($nmEdit -match "^\d{3}[A-D]\d{3}[A-Z]$"){
        $left=MySubstring -strIn $nmEdit -nCnt 7
        $right=MySubstring -strIn $nmEdit -nSta 7 -nCnt 1
        switch ($right) {
            {$_ -in ("H","N")}{$right= MyCharUp $right 2}
            "Z" {$right="AA"}
            default {$right= MyCharUp $right}
        }
        return $left + $right + $Extent
    }
    if($nmEdit -match "^\d{3}[A-D]\d{3}[A-H][A-Z]$"){
        $left=MySubstring -strIn $nmEdit -nCnt 7
        $mid=MySubstring -strIn $nmEdit -nSta 7 -nCnt 1
        $right=MySubstring -strIn $nmEdit -nSta 8 -nCnt 1
        switch ($right) {
            {$_ -in ("H","N")}{$right= MyCharUp $right 2}
            "Z" {$mid= MyCharUp $mid;$right="A"}
            default {$right= MyCharUp $right}
        }
        return $left + $mid + $right + $Extent
    }

}