Replace Number with Alphabet in C# and VB.Net

Last Reply 3 months ago By pandeyism

Posted 3 months ago

i want to convert number to alphabet in c#

for example

1=a

2=b

3=c

4=d

5=e

6=f

7=g

8=h

9=i

0=j

 

string 123221760

convert string=abcbbagfj

 

thank you

You are viewing reply posted by: pandeyism 3 months ago.
Posted 3 months ago

Hi anirudhp,

Refer below sample.

Code

C#

protected void Page_Load(object sender, EventArgs e)
{
    string num = "123221760";
    num = num.Replace("1", "a").Replace("2", "b").Replace("3", "c").Replace("4", "d").Replace("5", "e")
        .Replace("6", "f").Replace("7", "g").Replace("8", "h").Replace("9", "i").Replace("0", "j");
    Response.Write(num);
}

VB.Net

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    Dim num As String = "123221760"
    num = num.Replace("1", "a").Replace("2", "b").Replace("3", "c").Replace("4", "d").Replace("5", "e").Replace("6", "f").Replace("7", "g").Replace("8", "h").Replace("9", "i").Replace("0", "j")
    Response.Write(num)
End Sub

Output

abcbbagfj