开发者

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

开发者 https://www.devze.com 2023-02-17 02:18 出处:网络
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
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

精彩评论

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

关注公众号