[Java] Full-width ⇔ half-width conversion

·reference TERASOLUNA Server Framework for Java 7.6 String Processing

Add library

https://mvnrepository.com/artifact/org.terasoluna.gfw/terasoluna-gfw-string

maven


<!-- https://mvnrepository.com/artifact/org.terasoluna.gfw/terasoluna-gfw-string -->
<dependency>
    <groupId>org.terasoluna.gfw</groupId>
    <artifactId>terasoluna-gfw-string</artifactId>
    <version>5.6.1.RELEASE</version>
</dependency>

gradle


dependencies {
// https://mvnrepository.com/artifact/org.terasoluna.gfw/terasoluna-gfw-string
compile group: 'org.terasoluna.gfw', name: 'terasoluna-gfw-string', version: '5.6.1.RELEASE'
}

Don't forget to refresh your Gradle → Gradle project.

Convert from full-width to half-width

import org.terasoluna.gfw.common.fullhalf.DefaultFullHalf;

//Omission
        String halfwidth = DefaultFullHalf.INSTANCE.toHalfwidth(a Tachizudepu);//Voiced and semi-voiced sound marks are also OK
		System.out.println(halfwidth); //a Tachideppu

Convert from half-width to full-width

import org.terasoluna.gfw.common.fullhalf.DefaultFullHalf;

//Omission
        String fullwidth = DefaultFullHalf.INSTANCE.toFullwidth("A!A8 Gaza");
		System.out.println(fullwidth);//Ah! A8 Gaza

Other methods

Let's use Java character conversion library ICU4J About full-width ⇔ half-width conversion of character strings in Java There are other ways to convert with ICU4J or java.text.normalizer. With normalizer, full-width katakana → half-width katakana conversion could not be done

Recommended Posts

[Java] Full-width ⇔ half-width conversion
Full-width → half-width conversion with Java String (full-width kana → half-width kana)
About full-width ⇔ half-width conversion of character strings in Java
Java type conversion
Endian conversion with JAVA
[Java] Date type conversion
[Java] Align characters even with mixed half-width and full-width characters
[Java] List type / Array type conversion
[Java] Precautions for type conversion
[Java] Type conversion speed comparison
Full-width / half-width judgment regular expression
Java Primer Series (Type Conversion)
Java
Java
[Java] Conversion from array to List
Java array / list / stream mutual conversion list
Java8 list conversion with Stream map
Conversion between Kotlin nullable and Java Optional
Java date data type conversion (Date, Calendar, String)
[Easy-to-understand explanation! ] Reference type type conversion in Java
[Java ~ Variable definition, type conversion ~] Study memo
Java study # 3 (type conversion and instruction execution)
How to do base conversion in Java
[Basic knowledge of Java] About type conversion
Immutable (immutable) List object conversion function in Java8
Java 8 LocalDateTime type conversion stuff (String, java.util.Date)
[Java] Calculation mechanism, operators and type conversion
Type conversion from java BigDecimal type to String type