java - Increase a char value by one -


i have app edittext , button named "forward". want when type "a" in edittext , click button, word "b" typed in edittext, "c" if pressed again , on. have tried:

value = edt.gettext(); edt.settext(value + 1); 

but of course print initial string followed number "1". ideas? lot

tested , works

all letters can represented ascii values.

if cast letters int, add 1, , cast char, letter increase 1 ascii value (the next letter).

for example:

'a' 97
'b' 98

so if input 'a' , casted int, 97. add 1 , 98, , cast char again , 'b'.

here example of casting:

system.out.println( (int)('a') ); // 97 system.out.println( (int)('b') ); // 98 system.out.println( (char)(97) ); // system.out.println( (char)(98) ); // b 

so, final code might this:

// first char in input string char value = et.gettext().tostring().charat(0);  int nextvalue = (int)value + 1; // find int value plus 1  char c = (char)nextvalue; // convert char  et.settext( string.valueof(c) ); // print char string 

of course work if there 1 single character input.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -