Preeti
Preeti

Reputation: 1386

Generating next string from given string

I want to generate next character from given character. Eg : given charater = "A" next charater "B" to be generated programatically.

Upvotes: 0

Views: 99

Answers (2)

Doc Brown
Doc Brown

Reputation: 20044

Try this snippet:

 chr(Asc(yourCharacter)+1)

Upvotes: 1

Damien_The_Unbeliever
Damien_The_Unbeliever

Reputation: 239664

You may be able to move from one code point in Unicode to the next, but that may not match the users expectations, depending on their native language, so if there's a small, limited set of characters in which you wish to work, it's probably worth just holding that as a constant string and using IndexOf to match the current character:

Private Const CharRange as String = "ABCDE"

Public Function NextChar(ByVal CurrentChar as String) as String
    Return CharRange((CharRange.IndexOf(CurrentChar(0))+1) Mod CharRange.Length)
End Function

(I'm assuming you wish to loop back to the start when the last character is reached. That assumption also may not be true)


Unicode code point version (still may not be right in all circumstances, as mentioned above):

Public Function NextChar(ByVal CurrentChar As Char) As Char
    Return Convert.ToChar(Convert.ToInt32(CurrentChar) + 1)
End Function

Upvotes: 0

Related Questions