文字列(apellidoPat)の最初の母音を見つけたい場合たとえば、私の文字列が "CRUZ"の場合、拡張出力が "U"の場合、rfcで連結して何を使用できますか?ループ??
apellidoPatの最初の母音以外はすべて持っています
private String getRFC() {
String rfc = "";
String apellidoPat = "CRUZ";
String apellidoMat = "HERNANDEZ";
String nombre = "JAVIER";
String fechaNac = "1997-12-25";
rfc = apellidoPat.substring(0,1) + "FIST VOWEL apellidoPat" + apellidoMat.substring(0,1) + nombre.substring(0,1) + fechaNac.substring(2,4) + fechaNac.substring(5,7) + fechaNac.substring(8,10);
// Expected output: CUHJ971225
return rfc
}
を避けるために日付を部分ごとに追加する必要はありません。目的の結果を得るために-
、日付を分割して-
結合することをお勧めします。そして、ループを使用して最初の母音を見つけることができます:
private String getRFC(){
String vowels = "AEIOUaeiou";
String apellidoPat = "CRUZ";
String apellidoMat = "HERNANDEZ";
String fechaNac = "1997-12-25";
// first letter of apellidoPat
String rfc = String.valueOf(apellidoPat.charAt(0));
// first vowel of apellidoPat
for (int i = 0; i < apellidoPat.length(); ++i){
if (vowels.indexOf(apellidoPat.charAt(i)) != -1){
rfc += String.valueOf(apellidoPat.charAt(i));
break;
}
}
// first letter of apellidoMat + date (YYMMDD)
rfc += apellidoMat.charAt(0) + String.join("", fechaNac.split("-"));
return rfc;
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加