试图检查某个位置是否包含C#中的某个字符

时间:2016-12-12 13:16:10

标签: c# console-application

如果字符串包含点,我需要检查字符串的第三个和第四个位置。我不确定该怎么做。我是否使用string.Contains?我是否需要制作阵列?我对此非常困惑。

2 个答案:

答案 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

相关问题