Reputation: 285
I am using this to get each line from a text file using Java Class.
String line = null;
try{
BufferedReader Br=new BufferedReader(new FileReader("/data/local/fileconfig.txt"));
while ((line = Br.readLine()) != null)
{
Log.d("hi", "LINE : " + line);
}
} catch (Throwable throwable) { }
The fileconfig.txt has 2 lines like this -
############################################
packagename:com.hello
So my Log is like -
LINE : ############################################
LINE : packagename:com.hello
My question is now I am able to get this line info packagename:com.hello. I just want to extract com.hello out of this line. What is the logic I can use in my while loop?
Upvotes: 0
Views: 54
Reputation: 20019
You could use the startsWith() method.
Or, somewhat more powerful, but also more difficult, use Regular Expressions with Match Groups.
See here: Using Java to find substring of a bigger string using Regular Expression
Upvotes: 3
Reputation: 2117
You can use either RegEx or a simple split()
from String
:?(.*)
or split
String myString = "dsd:Example";
myString.split(":");
Upvotes: 1
Reputation: 30809
If the format of line is always the same then this should do:
Log.d("hi", "LINE : " + line.substring(line.lastIndexOf(":")+1));
Upvotes: 2