定位子串是指在一个字符串中寻找其中包含的子串或者某个字符,下面,逐一给大家详细介绍。 一、IndexOf/LastIndexOf IndexOf方法用于搜索在一个字符串中,某个特定的字符或者子串第一次出现的位置,该方法区分大小写,并从字符串的首字符开始以0计数。如果字符串中不包含这个字符或子串,则返回-1。常用的重载形式如下所示。 ①定位字符 int IndexOf(char value) int IndexOf(char value, int startIndex) int IndexOf(char value, int startIndex, int count)