this is the example text int text file
title: get this string and desc: get this string
I want to split it with "title:" and "desc:"
this is the example text int text file
title: get this string and desc: get this string
I want to split it with "title:" and "desc:"
it is simple : after getting file content (https://stackoverflow.com/a/14768380/1725748), do :
String mystring= "title: xxxxxx desc: yyyyy";
String[] splits = mystring.split("title:|desc:");
splits[0] // is the title
splits[1] // is the description
There are various ways to get a String how you like, here I found the index of desc and split the String where desc appears:
try{
InputStream inputStream = getResources().openRawResource(R.raw.textfile);
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String line;
String title_content, desc_content;
// Read each line
while((line = reader.readLine( )) != null)
{
// title: get this string and desc: get this string
// ^
// (desc_location)
int desc_location;
if((desc_location = line.indexOf("desc:")) > 0)
{
title_content = line.substring(0, desc_location);
desc_content = line.substring(desc_location, line.length( ));
}
}
} catch (Exception e) {
// e.printStackTrace();
}