如何检查最后一位数字是否为整数 [英] How Can I Check Whether The Last Digit Is Integer Or Not

查看:88
本文介绍了如何检查最后一位数字是否为整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查天气,字符串的最后位置是否为整数?



例如: -



String str =Hello123;



现在我如何检查最后一位3是整数还是字符串??



请帮助

解决方案

如果你唯一关心的是检查最后一个字符是数字还是字母,你可以使用方法 Char.IsDigit [ ^ ]





  bool  isDigit = Char.IsDigit(str, str.Length-1); 


试试这个 -

 字符串 str =   Hello123; 
str = str.Substring(str.Length - 1 );
int temp = 0 ;
if int .TryParse(str, out temp))
Console.WriteLine( Integer);
else
Console.WriteLine( 不是整数);





希望,它有帮助:)


您可以使用Char.IsDigitMethod()来测试

 字符串 str =   pankaj3; 
bool b = Char.IsDigit(str,str.Length - 1 );


how can i check weather the last position of a string is integer or not??

For Example:-

String str = "Hello123";

Now how can i check the last digit "3" is integer or string??

please help

解决方案

If your only concern is to check if the last character is a digit or alpha, you can use the method Char.IsDigit[^]

Like

bool isDigit = Char.IsDigit(str, str.Length-1);


Try this-

String str = "Hello123";
str = str.Substring(str.Length - 1);
int temp=0;
if(int.TryParse(str,out temp))
   Console.WriteLine("Integer");
else
   Console.WriteLine("Not Integer");



Hope, it helps :)


You can use Char.IsDigitMethod() to test

String str = "pankaj3";
bool b = Char.IsDigit(str,str.Length - 1);


这篇关于如何检查最后一位数字是否为整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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