Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

10
LINES

< > BotCompany Repo | #1004368 // lexicographicallyNextString

JavaX fragment (include)

1  
// credits to stackoverflow.com/users/1442960/marcus
2  
static S lexicographicallyNextString(S input) {
3  
  final int lastCharPosition = input.length()-1;
4  
  String inputWithoutLastChar = input.substring(0, lastCharPosition);
5  
  char lastChar = input.charAt(lastCharPosition);
6  
  char incrementedLastChar = (char) (lastChar + 1);
7  
  // Handle int/char overflow.  This wasn't done above.
8  
  if (incrementedLastChar == ((char) 0)) return input+incrementedLastChar;
9  
  return inputWithoutLastChar+incrementedLastChar;
10  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1004368
Snippet name: lexicographicallyNextString
Eternal ID of this version: #1004368/1
Text MD5: b009d1bcfc20da6a4f4aacea582521d7
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-08-14 15:53:43
Source code size: 514 bytes / 10 lines
Pitched / IR pitched: No / No
Views / Downloads: 559 / 550
Referenced in: [show references]