Android How To Subtract String From Given String
I'm getting string in button. text I want to display only specific character only but when click show full value in toast how I will do that? Button e01; String[] days = new String
Solution 1:
you can substract from the length.
Stringnumbers= days[1].substring(days[1].length() - 8);
the date is 10 characters, minus 2 it gives last 11
Solution 2:
If you want to show 11
from 2013/09/11
you can do it as -
String[] stringArray = days[1].split("/");
String elevenString = stringArray[stringArray.length-1];
Edit -
e01.setText(elevenString);
eo1.setTag(days[1]);
Now in onclick do this -
@OverridepublicvoidonClick(View v){
// TODO Auto-generated method stubswitch (v.getId()) {
case R.id.e01:
value = (String) e01.getTag();
Toast.makeText(this, value, Toast.LENGTH_SHORT).show();
//value=// 2013/09/11break;
}
}
Solution 3:
Since you are showing a date then year is 4 characters + 2 for month + 2 /,then total of 6 characters you can use subString like below
Toast.makeText(this, value.substring(5), Toast.LENGTH_SHORT).show();
This should work perfectly.
NB:- Never use this way if the string is variable,not like this one.
Solution 4:
String[] SeperatedDateValue= days[1].split("/");//days[1] = "2013/09/11"
/*SeperatedDateValue[0]//Year
SeperatedDateValue[1]//Month
SeperatedDateValue[0]//Day*/
e01.setText(SeperatedDateValue[0]);
And on Button Click
Display your date string as it is on the Toast by using your days[] variable values
Post a Comment for "Android How To Subtract String From Given String"