转换字符串数组为int [英] Converting string array to int

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

问题描述

我有一个奇怪的问题,试图从一个字符串数组字符串 并将其转换成一个整数。 看看这个code片断:

I'm having a weird problem, trying to take a string from a string array and convert it to an integer. Take a look at this code snippet:

string date = "‎21/‎07/‎2010 ‏‎13:50";
var date1 = date.Split(' ')[0];
string[] dateArray = date1.Split('/');

string s = "21";
string t1 = dateArray[0];

bool e = string.Compare(s, t1) == 0;        //TRUE

int good = Convert.ToInt32(s);            //WORKING!
int bad = Convert.ToInt32(t1);  //Format exception - Input string was not in a correct format.

有人可以解释为什么与S转换工作,同时与T1不成?

Can someone please explain why the conversion with s works, while with t1 fails?

推荐答案

您的字符串是充满了隐藏字符,导致其破裂。有四个 U + 200E 和一个 U + 200F

Your string is full of hidden characters, causing it to break. There's four U+200E and one U+200F

下面是一个干净的字符串尝试:

Here's a clean string to try on:

string date = "21/07/2010 13:50";

这篇关于转换字符串数组为int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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