开发者

Parsing a string-what should be the end-index for the newline?

Your request for ...

Good morning Mr Praneel PIDIKITI
you have succ.....

This is my string i want to parse this string in order to get the value Praneel PIDIKITI i am using

  int begin_index = 0;
    int end_index = 0;

    String startkeyword = "Good morning";
    String endKeyword = " ???";
    int main_begin_index = lines[i].indexOf(startkeyword, begin_index);
    begin_index = main_begin_index;
    end_index = lines[i].indexOf(endKeyword, begin_index);

    String Name= lines[i].substring(begin_index + startkeyw开发者_JAVA百科ord.length(), end_index).trim();

What should be my endKeyword as it is the end of the line ??? can anyone help me ....


You may be better off using Regexp for this.

    Pattern p = Pattern.compile("Good morning (.*)");
    Matcher m = p.matcher(line[i]);
    String name = "";
    if (m.find())
        name = m.group(1);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜