我必须分析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();
}
答案 0 :(得分: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];
}