查找某字符串特定索引位置的字符时什么
比如:
String a="abcde";
char c=a.charAt(1);
则c=‘b’
满意请采纳,谢谢!
Java中的string拥有CharAt()方法,C#是不拥有的
using System;
namespace Company{
public class TestMain{
static void Main(){
string str = "abcdefg";
string n_str = str.CharAt(3);
Console.WriteLine(n_str);
}
}
public static class CharAtExtention{
public static string CharAt(this string s,int index){
if((index >= s.Length)||(index<0))
return "";
return s.Substring(index,1);
}
}
}
这样,直接取字符串中指定位置的字符就非常方便了。