62,046
社区成员
发帖
与我相关
我的任务
分享
string test = "ababa";
int index = test.IndexOf("a");
if (index > -1)
{
test = test.Remove(index, 1).Insert(index, "*");
}
string test = "ababa";
int index = test.IndexOf("a");
if (index > -1)
{
int a= test .IndexOf("a", test .IndexOf("a") + 1);
test = test .Remove(a,1).Insert(a, "*");
}
string test = "ababa";
int count = test.ToCharArray().Length;
for (int i = 0; i < test.ToCharArray().Length; i++)
{
if (i == count / 2)
{
Response.Write(test.ToCharArray()[i].ToString().Replace("a", "*").ToString());
}
else
{
Response.Write(test.ToCharArray()[i].ToString());
}
}
void Main()
{
string test = "ababa";
test=Regex.Replace(test,"(a[^a])a","$1*");
Console.WriteLine(test);//ab*ba
}