2011-03-15 37 views
0
Your request for ... 

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

这是我的字符串我想,以获得价值Praneel PIDIKITI 解析这个字符串,我使用解析一个字符串 - 什么应该是换行符的结束索引?

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 + startkeyword.length(), end_index).trim(); 

应该是什么我endKeyword,因为它是该行的末尾??? 任何人都可以帮助我....

+2

是否有没有使用'indexOf'为'Mr Praneel PIDIKITI''字符串? – PaoloVictor 2011-03-15 11:28:37

+0

你已经知道这个字符串包含你的名字。为什么不像PaoloVictor建议的那样提取它? – adarshr 2011-03-15 11:29:24

+0

我猜这个名字不会每次都是一样的 – Belinda 2011-03-15 11:40:40

回答

2

您可能会更好使用正则表达式。

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