替换字符串中不敏感的最佳方法 [英] best way for Replace insensitive in strings

查看:92
本文介绍了替换字符串中不敏感的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要替换另一个字符串中所有字符串的出现

(或stringbuilder):


函数ReplaceInsensitive(ByVal InputString As String,_

ByVal SubstringReplaced As

String,_

ByVal替换为

String)As String

''...

结束功能


我希望搜索SubstringReplaced"不区分大小写。


我能想出各种各样的方法来做到这一点,但我能想到的只是非常尴尬。有人能建议一个好的,快速的方法吗?必须有

用语言构建的东西,但我很想念它


-Pam

I need to replace all the occurences of a string within another string
(or stringbuilder):

Function ReplaceInsensitive(ByVal InputString As String, _
ByVal SubstringReplaced As
String, _
ByVal Replacement As
String) As String
''...
End Function

I wish the search for "SubstringReplaced" to be case insensitive.

I can think of various way to do it, but all I can think is quite
awkward. Can anybody suggest a good and fast method? There must be
something built in the language, but I am missing it

-Pam

推荐答案

pa *********** @ libero .it 写道:
我希望搜索SubstringReplaced"不区分大小写。
I wish the search for "SubstringReplaced" to be case insensitive.




\\\

函数ReplaceInsensitive(ByVal InputString As String,_

ByVal SubstringReplaced As String,

_

ByVal Replacement As String)As

String


返回替换(InputString,SubStringReplaced,_

替换,比较:= CompareMethod.Text)


结束函数

// /


-


(O)enone



\\\
Function ReplaceInsensitive(ByVal InputString As String, _
ByVal SubstringReplaced As String,
_
ByVal Replacement As String) As
String

Return Replace(InputString, SubStringReplaced, _
Replacement, Compare:=CompareMethod.Text)

End Function
///

--

(O)enone


未经测试


函数ReplaceInsensitive(ByVal InputString As String,_

ByVal

SubstringReplaced As String,_

ByVal替换为

字符串)作为字符串


返回InputString.Replace(SubstringReplaced,Replacement)

结束函数
< a href =mailto:pa *********** @ libero.it> pa *********** @ libero.it 写道:
我需要替换另一个字符串中所有出现的字符串string
(或stringbuilder):

函数ReplaceInsensitive(ByVal InputString As String,_
ByVal SubstringReplaced As
String,_
ByVal Replacement As
String)As String
''...
结束函数

我希望搜索SubstringReplaced"不区分大小写。

我可以想到各种方法来做到这一点,但我能想到的只是很尴尬。有人能建议一个好的,快速的方法吗?必须有语言内置的东西,但我想念它

-Pam
I need to replace all the occurences of a string within another string
(or stringbuilder):

Function ReplaceInsensitive(ByVal InputString As String, _
ByVal SubstringReplaced As
String, _
ByVal Replacement As
String) As String
''...
End Function

I wish the search for "SubstringReplaced" to be case insensitive.

I can think of various way to do it, but all I can think is quite
awkward. Can anybody suggest a good and fast method? There must be
something built in the language, but I am missing it

-Pam








(O)enone提供的版本工作正常。感谢您的帮助!


(艾哈迈德的建议是在正确的轨道上,省略CompareMethod是

喜欢:比较:= CompareMethod.Binary)

对于使用StringBuilder的情况,是否有任何提示?


Sub ReplaceInsensitive(ByVal Sb As System.Text.StringBuilder,_

ByVal SubstringReplaced As String,_

ByVal Replacement As String)

''...

End Sub

非常感谢。


-Pam


The version provided by (O)enone works fine. Thanks for the help!

(Ahmed suggestion is on the right track, omitting the CompareMethod is
like: Compare:=CompareMethod.Binary)
Any hint, instead, for the case when a StringBuilder is used?

Sub ReplaceInsensitive(ByVal Sb As System.Text.StringBuilder, _
ByVal SubstringReplaced As String, _
ByVal Replacement As String)
''...
End Sub
Thank you very much.

-Pam


这篇关于替换字符串中不敏感的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆