开发者

Read from a string until specific char in Android

How can I read numbers from a string until I find a specific char, in my case - a dot.

For example I have a

String date = "18.8.2011"
int mDay = 0;
int mMonth = 0;
int mYear = 0;

And I want to make mDay = 18, mMonth = 8 and mYear = 2011 - I want 开发者_开发百科to be able to copy the digits until I find a dot.


Use split method of String class.

String []ar=date.split("[.]");
int mDay=Integer.parseInt(ar[0]);
..


String[] arr = date.split("[.]");

int mDay = Integer.parseInt(arr[0]);
int mMonth = Integer.parseInt(arr[1]);
int myear = Integer.parseInt(arr[2]);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜