第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

從全文中檢索字符串的一部分

從全文中檢索字符串的一部分

臨摹微笑 2022-12-28 11:09:03
我有一個(gè)字符串變量,其中包含一個(gè)文本以及其中的一些日期。現(xiàn)在我想從文本中檢索日期。我該怎么做。String a ="I am ready at time -S 2019-06-16:00:00:00 and be there"現(xiàn)在我想2019-06-16:00:00:00從那里取回。日期格式將始終采用相同的格式,但我只需要從文本中檢索日期。
查看完整描述

4 回答

?
江戶川亂折騰

TA貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超5個(gè)贊

嘗試使用帶有模式的正則表達(dá)式匹配器:


\d{4}-\d{2}-\d{2}:\d{2}:\d{2}:\d{2}

示例代碼:


String a = "I am ready at time -S 2019-06-16:00:00:00 and be there";

String pattern = "\\d{4}-\\d{2}-\\d{2}:\\d{2}:\\d{2}:\\d{2}";

Pattern r = Pattern.compile(pattern);

Matcher m = r.matcher(a);

while (m.find()) {

     System.out.println("found a timestamp: " + m.group(0));

}


查看完整回答
反對(duì) 回復(fù) 2022-12-28
?
嚕嚕噠

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超7個(gè)贊

使用正則表達(dá)式從文本中檢索日期。


public static void main(String[] args) {

    String a = "I am ready at time -S 2019-06-16:00:00:00 and be there";

    Pattern pattern = Pattern.compile("[0-9]{4}[-][0-9]{1,2}[-][0-9]{1,2}[:][0-9]{1,2}[:][0-9]{1,2}[:][0-9]{1,2}");

    Matcher matcher = pattern.matcher(a);

    while(matcher.find()){

        System.out.println(matcher.group());

    }

}


查看完整回答
反對(duì) 回復(fù) 2022-12-28
?
弒天下

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超8個(gè)贊

String str = "I am ready at time -S 2019-06-16:00:00:00 and be there";

Pattern pattern = Pattern.compile("(?<date>\\d{4}-\\d{2}-\\d{2}):(?<time>\\d{2}:\\d{2}:\\d{2})");

Matcher matcher = pattern.matcher(str);


if(matcher.matches()) {

    System.out.println(matcher.group("date"));  // 2019-06-16

    System.out.println(matcher.group("time"));  // 00:00:00

}


查看完整回答
反對(duì) 回復(fù) 2022-12-28
?
鴻蒙傳說(shuō)

TA貢獻(xiàn)1865條經(jīng)驗(yàn) 獲得超7個(gè)贊

我建議為此使用正則表達(dá)式,如下所示:


private static final Pattern p = Pattern.compile("(\d{4}-\d{2}-\d{2}:\d{2}:\d{2}:\d{2})");

public static void main(String[] args) {


    String a = "I am ready at time -S 2019-06-16:00:00:00 and be there"


    // create matcher for pattern p and given string

    Matcher m = p.matcher(a);


    // if an occurrence if a pattern was found in the given string...

    if (m.find()) {

        // ...then you can use group() methods.

        System.out.println(m.group(0));

    }

}


查看完整回答
反對(duì) 回復(fù) 2022-12-28
  • 4 回答
  • 0 關(guān)注
  • 143 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)