相关疑难解决方法(0)

有String.Replace的方法只打了"整个单词"

我需要一种方法来做到这一点:

"test, and test but not testing.  But yes to test".Replace("test", "text")
Run Code Online (Sandbox Code Playgroud)

归还这个:

"text, and text but not testing.  But yes to text"
Run Code Online (Sandbox Code Playgroud)

基本上我想替换整个单词,但不是部分匹配.

注意:我将不得不使用VB(SSRS 2008代码),但C#是我的正常语言,因此两者中的响应都很好.

.net c# vb.net string

69
推荐指数
4
解决办法
6万
查看次数

仅在100%匹配时替换字符串

只是徘徊,仅在c#.net中100%匹配时才如何替换字符串?例如,我有以下字符串:

StringBuilder a = new(StringBuilder);     
a = "ABC-1 ABC-1.1 ABC-1.1~1"
Run Code Online (Sandbox Code Playgroud)

我正在使用以下脚本替换字符串:

a.Replace("ABC-1", "ABC-2");
Run Code Online (Sandbox Code Playgroud)

此刻输出如下:

ABC-2 ABC-2.1 ABC-2.1~1
Run Code Online (Sandbox Code Playgroud)

相反,我正在寻找类似的输出:

ABC-2 ABC-1.1 ABC-1.1~1
Run Code Online (Sandbox Code Playgroud)

有人知道我该怎么做吗?

.net c#

2
推荐指数
1
解决办法
161
查看次数

标签 统计

.net ×2

c# ×2

string ×1

vb.net ×1