Skip to content

Instantly share code, notes, and snippets.

@webgio
Created December 20, 2012 09:10
Show Gist options
  • Save webgio/4344033 to your computer and use it in GitHub Desktop.
Save webgio/4344033 to your computer and use it in GitHub Desktop.
Lexicographical next string, to use for autocomplete searches with startkey and endkey parameters. (CouchDb, Azure Storage tables ... )
public static string LexicographicallyNextString(string starting)
{
starting = starting.ToLowerInvariant();
char last = starting[starting.Length - 1];
int position = last;
int next = ++position;
char nextChar = (char)next;
string endStarting = starting.Substring(0, starting.Length - 1) + nextChar.ToString();
return endStarting;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment