An open API service indexing awesome lists of open source software.

https://github.com/mk3008/hankaku

Half-width(hankaku) conversion, half-width(hankaku) character count function
https://github.com/mk3008/hankaku

conversion half-width hankaku string

Last synced: 3 months ago
JSON representation

Half-width(hankaku) conversion, half-width(hankaku) character count function

Awesome Lists containing this project

README

        

# Hankaku
半角変換と文字数カウント関数を提供します。

## デモンストレーション
```cs
using Hankaku;

Console.WriteLine("半角変換したい文字列を入力後、Enterキーを押してください。");
var input = Console.ReadLine();
input ??= string.Empty;

Console.WriteLine("入力値   : " + input);

// 半角変換後の文字列を取得
var hankakuText = input.ToHankaku();
Console.WriteLine("半角変換後 : " + hankakuText);

// 半角文字数カウント
Console.WriteLine("カウント半角: " + hankakuText.CountHankaku());
```

### 結果
```
半角変換したい文字列を入力後、Enterキーを押してください。
ヤマダタロウ
入力値   : ヤマダタロウ
半角変換後 : ヤマダタロウ
カウント半角: 7
```

## 機能
- 文字列を半角文字列に変換できます。
- 半角変更できる文字列は英数字、記号(スペース含む)、日本語カナのみです。
- 文字列を半角文字なら1、それ以外を2としてカウントすることができます。
- 文字列を左から半角文字数分だけ切り出しすることができます。残りも文字列の取得もできます。

## インストール
[Nugetからインストールできます。](https://www.nuget.org/packages/Hankaku)
```
PM> Install-Package Hankaku
```

## 使い方

### ToHankaku メソッド
与えられた文字列内の全角文字を半角文字に変換します。
```cs
public static string ToHankaku(this string text)
```

### CountHankaku メソッド
与えられた文字列内の日本語半角文字を1、それ以外を2としてカウントします。
```cs
public static int CountHankaku(this string text)
```

### LeftHankaku メソッド
文字列を左から半角文字数分切り出します。
```cs
public static string LeftHankaku(this string text, int hankakuCount)
```

文字列を左から半角文字数分切り出し、残った文字列も取得します。
```cs
public static string LeftHankaku(this string text, int hankakuCount, out string remainingText)
```