现在
string str="asdfAAAasldjAAAflaAAAsjd\nasdAAAfkjAAAhsdf"string str2="BBB"我现在要用str2替换首个AAA结果"asdBBBasldjAAAflaAAAsjd\nasdAAAfkjAAAhsdf"
string str="asdfAAAasldjAAAflaAAAsjd\nasdAAAfkjAAAhsdf"string str2="BBB"我现在要用str2替换首个AAA结果"asdBBBasldjAAAflaAAAsjd\nasdAAAfkjAAAhsdf"
解决方案 »
- 关于用户控件中子控件用updatepanel异步刷新页面,很怪!
- ASP.NET MVC中 关于 客户端验证机制的问题
- 100分,“为什么都说VS2005 Team Suite版 自带了 Visio VSS,可是我就是没有 ”,在线,解决了,立即给200分。
- (100分)网页错误提示:服务器无法在发送HTTP标头之后清除标头。请问怎么解决?
- 如何用CustomValidator来验证listbox
- asp.net如何实现产品的无限级分类?
- 求助 数据库插记录的问题
- 怎么编程把足球盘口里面的水位搞下来
- 如何用asp.net将文本文件中的数据导入数据库
- 继续求一条sql语句,发现上次那条不能解决我的问题
- ajax实现数据加载中提示功能
- socket 怎么外网对内网交互数据
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;namespace ConsoleApplication9
{
class Program
{
static void Main(string[] args)
{
string str="asdfAAAasldjAAAflaAAAsjd\nasdAAAfkjAAAhsdf";
string str2="BBB";
string newstr = str.Substring(0, str.IndexOf("AAA") + 3).Replace("AAA", str2);
Console.WriteLine(newstr + str.Substring(str.IndexOf("AAA") + 3));
}
}
}
string str = "asdfAAAasldjAAAflaAAAsjd\nasdAAAfkjAAAhsdf";
string str2 = "BBB";
int index = str.IndexOf("AAA");
string result = str.Remove(index, "AAA".Length);
result = result.Insert(index, str2);
Response.Write(result);
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;namespace ConsoleApplication9
{
class Program
{
static void Main(string[] args)
{
string str="asdfAAAasldjAAAflaAAAsjd\nasdAAAfkjAAAhsdf";
string str2="BBB";
Regex rgx = new Regex(@"AAA");
Console.WriteLine(rgx.Replace(str, str2,1));
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;namespace ConsoleApplication9
{
class Program
{
static void Main(string[] args)
{
string str="asdfAAAasldjAAAflaAAAsjd\nasdAAAfkjAAAhsdf";
string str2="BBB";
Regex rgx = new Regex(@"AAA");
Console.WriteLine(rgx.Replace(str, str2,1));
/*
* 输出结果:
* asdfBBBasldjAAAflaAAAsjd
* asdAAAfkjAAAhsdf
*/
}
}
}
测试通过完全没有问题啊。。
//正则当然也是可以实现的
void Main()
{
string str="asdfAAAasldjAAAflaAAAsjd\nasdAAAfkjAAAhsdf";string str2="BBB";
Regex reg=new Regex("AAA");
str=reg.Replace(str,str2,1);
Console.WriteLine(str);
/*
asdfBBBasldjAAAflaAAAsjd
asdAAAfkjAAAhsdf
*/
}