// IPv4アドレスを整形 (111.11.01.001 → 111.11.1.1)
public static String formatIPv4Address(String ipAddress) {
String[] octets = ipAddress.split('\\.');
if (octets.size() != 4) {
return null;
}
String formattedIpAddress = '';
for (Integer i = 0; i < 4; i++) {
if (i != 0) {
formattedIpAddress += '.';
}
formattedIpAddress += Integer.valueOf(octets[i]).toString();
}
return formattedIpAddress;
}
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme