Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
please help me for creating a code that is conversion of string to integer .if i enterd the value of a then o/p is 01,b then 02....z then 26 and if i enter the reverse that is 15 then o/p is h i require a code for it
Posted
Updated 27-Feb-14 22:53pm
v2

C#
 List<string> stringList = new List<string>();
 stringList.AddRange(new string[] { "1", "2", "3", "4", "sdfsf", "7" }); // for illustration
 int temp;
 var yourIntegerList = stringList.Select(x => int.TryParse(x, out temp) ? int.Parse(x) : -1).ToList(); // -1 used here, can be any integer
var  Finallylist = yourIntegerList.Where(a => a != -1).ToList();

foreach (var item in Finallylist)
{
    Console.WriteLine(item);
}
Console.ReadKey();




output:

only Integers from the list.
 
Share this answer
 
v2
use below code and change as per ur requirement
C#
string alphabets = " abcdefghijklmnopqrstuvwxyz";
int loc = alphabets.IndexOf('z');
string alphabet = alphabets[loc].ToString();
 
Share this answer
 
C#
int value;
char c;

string input = Console.ReadLine();
if (int.TryParse(input, out value))
{
    c = (char)('a' + value - 1);
    Console.WriteLine("{0}", c);
}
else
{
    c = input.ToLower()[0];
    value = c - 'a' + 1;
    Console.WriteLine("{0:00}", value);
}
 
Share this answer
 
Comments
Member 10631910 28-Feb-14 13:49pm    
hello, here only 1st letter of the string is converted to integer value i want all letters of enterd strin are in integer value and integer value to string value
Richard MacCutchan 28-Feb-14 14:05pm    
Well that should not be too difficult to figure out; I have done the hard part for you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900