-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 に答える