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?
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 --.
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.
Instead of whole strings, use Char
.
char aChar = 'A';
aChar++; // After this line executes, `aChar` is `B`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With