Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increment character in string

Tags:

c#

I have the following code:

string str="A";

I want to get the next alphabetical character programmatically (so B, C, D, E etc.)

Can anyone suggest a way of doing this?

like image 422
Rashmi Salokhe Avatar asked Oct 11 '12 11:10

Rashmi Salokhe


People also ask

Can you increment characters in C++?

The increment operator in C++ is ++. In fact, that's why C++ is called C++, because it is meant to be one better than C. Decrease the value of a variable by one. The decrement operator in C++ is --.

Can you increment a string in Python?

Because strings, like integers, are immutable in Python, we can use the augmented assignment operator to increment them. This process works similar to string concatenation, where normally you'd add two strings together.


1 Answers

Instead of whole strings, use Char.

char aChar = 'A';

aChar++; // After this line executes, `aChar` is `B`
like image 108
Oded Avatar answered Sep 30 '22 15:09

Oded