簡體   English   中英

從第一個大寫字母拆分字符串

[英]Split the string from first Upper case letter

我想使用 java 從此文本中提取文件名和時間戳

invoice_12890.pdf2019 年 4 月 10 日上午 8:33:16

預計

  • invoice_12890.pdf
  • 2019 年 4 月 10 日上午 8:33:16
boolean hadDot=false;//this makes sure we don't split before finding the file extension
String file="",date="";
for(int i=0;i<text.length();i++){
  if(text.charAt(i)=='.'){
    hadDot=true;
    continue;
  }
  if(hadDot&&Character.isUpperCase(text.charAt(i))){
    file=text.substring(0,i);
    date=text.substring(i);
    break;
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM