データベース テーブルに asD-101
や などの文字列型のデータがありD-102
ます。フロントエンド(JSF Webアプリケーション)で次のデータを自動的に取得して、データベースに送信したいD-103
.
このために、文字列から int データのみを取得したいと考えています。
これどうやってするの?
データベース テーブルに asD-101
や などの文字列型のデータがありD-102
ます。フロントエンド(JSF Webアプリケーション)で次のデータを自動的に取得して、データベースに送信したいD-103
.
このために、文字列から int データのみを取得したいと考えています。
これどうやってするの?
final Pattern lastIntPattern = Pattern.compile("[^0-9]+([0-9]+)$");
String input = D101;
Matcher matcher = lastIntPattern.matcher(input);
if (matcher.find()) {
String someNumberStr = matcher.group(1);
int lastNumberInt = Integer.parseInt(someNumberStr);
System.out.println("Test int output - " + lastNumberInt);
inputList.add(lastNumberInt);
}
次に、最大値を比較します
int currentBranchCode = 0;
for (Integer CCS : companyArrayList) {
if (currentBranchCode <= CCS) {
currentBranchCode = CCS;
}
}
その後
currentBranchCode =currentBranchCode +1;
String codegenerate="D"+currentBranchCode;
絶対試して。
マネージド Bean では、split()
関数を使用できます。
String s = "D-101";
String[] arr = s.split("[^\\d]+");
System.out.println(arr[1]); //prints 101
また
xhtml ページでは、次のような EL を記述できます。myBeanは Bean の名前であり、getColumnValue()メソッドは列の値 (つまり、「D-101」) を返すことに注意してください。
#{myBean.columnValue.split('[^\\d]+')[1]}
これは、数行で実行できます。
int i = Intger.parseInt(input.replaceAll(".*(?<!\\d)(\\d+)", "$1");
String next = input.replaceAll("(.*)(?<!\\d)\\d+", "$1"+ ++i);