如果字符串包含点,我需要检查字符串的第三个和第四个位置。我不确定该怎么做。我是否使用string.Contains?我是否需要制作阵列?我对此非常困惑。
答案 0 :(得分:2)
您正在寻找绝对位置,因此 // GET api/User/5
[ResponseType(typeof(UserModel))]
public IHttpActionResult GetUser(Guid id)
{
var item = repository.Get(id);
if (item == null)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
else
{
return Ok(item);
}
}
// GET api/User/GetCities/5
[ResponseType(typeof(CityModel))]
public IHttpActionResult GetCities(int id)
{
var item = repository.GetCities(id);
if (item == null)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
else
{
return Ok(item);
}
}
不会这样做,只有Contains
和[..]
:
Length
答案 1 :(得分:-1)
yourString.IndexOf(“。”,yourString.Length - 5,2)!= -1