我想要一个代码转换字符串为整数和反转在C# [英] i want a code for convertin string to integer and reverse in C#

查看:83
本文介绍了我想要一个代码转换字符串为整数和反转在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮我创建一个将字符串转换为整数的代码。如果我输入a的值那么o / p是01,b然后是02 .... z然后26如果我输入反向是15然后o / p为hi需要代码

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

推荐答案

 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.


使用下面的代码并根据您的要求进行更改

use below code and change as per ur requirement
string alphabets = " abcdefghijklmnopqrstuvwxyz";
int loc = alphabets.IndexOf('z');
string alphabet = alphabets[loc].ToString();


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);
}


这篇关于我想要一个代码转换字符串为整数和反转在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆