落木萧萧 发表于 2008-6-10 12:45

怎样的string[ ]中的值转换成int?

using System;
using System.IO;
class A
{
    public static void Main(string[] args)
    {
        FileStream fs = new FileStream(@"f:\\test.txt", FileMode.Open, FileAccess.Read);
        StreamReader sr = new StreamReader(fs);
        sr.BaseStream.Seek(0, SeekOrigin.Begin);
        string str1 = sr.ReadLine();
        string[] str2 = new string[10];
        int x;
        int Count = 0;
        while (str1 != null)
        {

            x = str1.IndexOf("R");
            if (x < 0) x = 0;
            str2[Count] = str1.Substring(x+7, 3);
            Count++;
            str1 = sr.ReadLine();
        }

        for (int i = 0; i < Count; i++)
        {
            Console.WriteLine(str2[i]);
        }
    }
}
运行这段代码将输出:100
怎样把100转换成int型?

野比 发表于 2008-6-10 12:57

Convert.ToInt32(string)

lijunwsp 发表于 2008-6-10 16:44

可以查msdn或者百度

xyq701830 发表于 2008-6-24 23:00

ing.parse();

gxlinhai 发表于 2008-6-26 16:48

Convert.ToInt32(string)
或者:
Int.Parse(string);

雪雨星风 发表于 2008-6-27 18:20

(int)

admin312 发表于 2008-7-3 23:10

int.Parse(string)  或   Convert.toInt32(string) 两个方法都可以

ruanjian2110 发表于 2008-7-3 23:39

ls正解
int.Parse(string)  或   Convert.toInt32(string) 两个方法都可以

页: [1]

编程论坛