-3

我必须分析 12 位数字。所以我被困在第 7 和第 8 个数字之间。我想如果数字是 40(数字 7 是 4,数字 8 是 0)给我“ex.London”,如果是 45 给我“ex.NY”......

代码 :

    [WebMethod]
    public string ID(string number)
    {
        int fullInt = Int32.Parse(number);
        string City1= number.Substring(0, 2);
        string City1_S = "Date of birth: " + City1;

        string City2 = number.Substring(2,2);
        string City2_S = "Month: " + City2;

        string City3 = number.Substring(4, 3);
        string City3_S = "Year: 1" + City3;

        string City4 = number.Substring(7, 2).Contains("40").ToString();
        string City4_S = "City: London";

        string[] Array= new string[3];
        Array[0] = City1_S.ToString();
        Array[1] = City2_S.ToString();
        Array[2] = City3_S.ToString();
        Array[3] = City4_S.ToString();

        return Array.ToString();
    }
4

1 回答 1

3
[WebMethod]
public string ID(string number)
{
    int fullInt = Int32.Parse(number);// if (Regex.IsMatch(number, @"\D")) throw new ArgumentException();
    string City1_S = "Date of birth: " + number.Substring(0, 2);
    string City2_S = "Month: " + number.Substring(2,2);
    string City3_S = "Year: 1" + number.Substring(4, 3);

    string City4_S = "";
    var digitStr = number.Substring(7, 2);
    switch (digitStr)
    {
        case "40":
             City4_S = "City: London";
             break;
        case "45":
             City4_S = "City: NY";
             break;
    }

    string[] Array = new [] { City1_S,  City2_S, City3_S, City4_S };

    return Array.ToString();//something wrong =)
    //return string.Join(" ", Array);
    //return Array[0] + " " + Array[1] + " " + Array[2] + " " + Array[3];
}
于 2012-12-23T17:22:23.103 回答