android app Search operation with broken words
Hi i am doing a search operation in the app using a specific keyword and listing the result in a list view activity. The result will be displayed with 50 characters before and after the searched keyword but when i take 50 characters it breaks the words and in the result half words or single letters are displayed in the beginning and after. How could i ignore and get 开发者_StackOverflowcomplete words
Below is my code. please do help me on this. thanks in advance
int endindex = searchTextStartIndex + searchTextLength + 50;
if (searchTextStartIndex > 50) {
startindex = searchTextStartIndex - 50;
}
if (endindex > datalength) {
endindex = datalength;
}
searchdata = searchdata.substring(startindex, endindex);
} catch (Exception e)
Assuming a space as word seperator:
if (searchTextStartIndex > 50) {
startindex = searchdata.lastIndexOf( " ", (searchTextStartIndex - 50) );
}
if (startindex == -1) startindex = 0;
int endindex = searchdata.indexOf( " ", (searchTextStartIndex + searchTextLength + 50) );
if (endindex == -1 || endindex > datalength) {
endindex = datalength;
}
searchdata = searchdata.substring(startindex, endindex);
精彩评论