473,597 Members | 2,301 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

best way for Replace insensitive in strings

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

Function ReplaceInsensit ive(ByVal InputString As String, _
ByVal SubstringReplac ed As
String, _
ByVal Replacement As
String) As String
'...
End Function

I wish the search for "SubstringRepla ced" 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

Jun 13 '06 #1
10 9586
pa***********@l ibero.it wrote:
I wish the search for "SubstringRepla ced" to be case insensitive.


\\\
Function ReplaceInsensit ive(ByVal InputString As String, _
ByVal SubstringReplac ed As String,
_
ByVal Replacement As String) As
String

Return Replace(InputSt ring, SubStringReplac ed, _
Replacement, Compare:=Compar eMethod.Text)

End Function
///

--

(O)enone
Jun 13 '06 #2
NOT TESTED

Function ReplaceInsensit ive(ByVal InputString As String, _
ByVal
SubstringReplac ed As String, _
ByVal Replacement As
String) As String

Return InputString.Rep lace(SubstringR eplaced, Replacement)
End Function
pa***********@l ibero.it wrote:
I need to replace all the occurences of a string within another string
(or stringbuilder):

Function ReplaceInsensit ive(ByVal InputString As String, _
ByVal SubstringReplac ed As
String, _
ByVal Replacement As
String) As String
'...
End Function

I wish the search for "SubstringRepla ced" 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


Jun 13 '06 #3

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:=Compar eMethod.Binary)
Any hint, instead, for the case when a StringBuilder is used?

Sub ReplaceInsensit ive(ByVal Sb As System.Text.Str ingBuilder, _
ByVal SubstringReplac ed As String, _
ByVal Replacement As String)
'...
End Sub
Thank you very much.

-Pam

Jun 13 '06 #4
Samething,
sb.Replace(subs tringreplaced, replacement)
pa***********@l ibero.it wrote:
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:=Compar eMethod.Binary)
Any hint, instead, for the case when a StringBuilder is used?

Sub ReplaceInsensit ive(ByVal Sb As System.Text.Str ingBuilder, _
ByVal SubstringReplac ed As String, _
ByVal Replacement As String)
'...
End Sub
Thank you very much.

-Pam


Jun 13 '06 #5
mmm ... no, remember the condition that it must be "case insensitive".
I don't see an option to specify it with the StringBuilder Replace
method (but I may be missing it (?) ).

-P

Ahmed ha scritto:
Samething,
sb.Replace(subs tringreplaced, replacement)
pa***********@l ibero.it wrote:
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:=Compar eMethod.Binary)
Any hint, instead, for the case when a StringBuilder is used?

Sub ReplaceInsensit ive(ByVal Sb As System.Text.Str ingBuilder, _
ByVal SubstringReplac ed As String, _
ByVal Replacement As String)
'...
End Sub
Thank you very much.

-Pam


Jun 13 '06 #6
Return Replace(sb.tost ring, SubStringReplac ed, _
Replacement, Compare:=Compar eMethod.Text)

pa***********@l ibero.it wrote:
mmm ... no, remember the condition that it must be "case insensitive".
I don't see an option to specify it with the StringBuilder Replace
method (but I may be missing it (?) ).

-P

Ahmed ha scritto:
Samething,
sb.Replace(subs tringreplaced, replacement)
pa***********@l ibero.it wrote:
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:=Compar eMethod.Binary)
Any hint, instead, for the case when a StringBuilder is used?

Sub ReplaceInsensit ive(ByVal Sb As System.Text.Str ingBuilder, _
ByVal SubstringReplac ed As String, _
ByVal Replacement As String)
'...
End Sub
Thank you very much.

-Pam


Jun 14 '06 #7
mmm ... Nice try Ahmed, but note that we are working with a
StringBuilder (infact, I proposed a *Sub* and *not* a Function). The
usefulness of a stringbuilder is that we have an immutable string, if
we convert it to a string, there is no point in using a StringBuilder.

-Pam

Ahmed ha scritto:
Return Replace(sb.tost ring, SubStringReplac ed, _
Replacement, Compare:=Compar eMethod.Text)


Jun 14 '06 #8
Hello Pam-o,

Yer changing schtuff in the string by the very definition of "replace", so
your precious immutable string.. aint so immuted anymore.

-Boo
mmm ... Nice try Ahmed, but note that we are working with a
StringBuilder (infact, I proposed a *Sub* and *not* a Function). The
usefulness of a stringbuilder is that we have an immutable string, if
we convert it to a string, there is no point in using a StringBuilder.

-Pam

Ahmed ha scritto:
Return Replace(sb.tost ring, SubStringReplac ed, _
Replacement, Compare:=Compar eMethod.Text)

Jun 14 '06 #9
Pamela,

If it are only words with a first upercase, I would just do it twice.

Otherwise Regex will be your needed tool.

RegexLib
http://www.regexlib.com/Default.aspx

Expresso
http://www.ultrapico.com/Expresso.htm

It needs a real hobbyist to help you then with your problem.

I hope this helps a little bit?

Cor
<pa***********@ libero.it> schreef in bericht
news:11******** **************@ f6g2000cwb.goog legroups.com...
mmm ... no, remember the condition that it must be "case insensitive".
I don't see an option to specify it with the StringBuilder Replace
method (but I may be missing it (?) ).

-P

Ahmed ha scritto:
Samething,
sb.Replace(subs tringreplaced, replacement)
pa***********@l ibero.it wrote:
> 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:=Compar eMethod.Binary)
>
>
> Any hint, instead, for the case when a StringBuilder is used?
>
> Sub ReplaceInsensit ive(ByVal Sb As System.Text.Str ingBuilder, _
> ByVal SubstringReplac ed As String, _
> ByVal Replacement As String)
> '...
> End Sub
>
>
> Thank you very much.
>
> -Pam

Jun 14 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
11298
by: hagai26 | last post by:
I am looking for the best and efficient way to replace the first word in a str, like this: "aa to become" -> "/aa/ to become" I know I can use spilt and than join them but I can also use regular expressions and I sure there is a lot ways, but I need realy efficient one
1
3153
by: ajay.sonawane | last post by:
How can I find the wheather the occurance substring is main string in wide char provided that the compasion should be case insensitive.
1
4222
by: Ron James | last post by:
I have a Listbox containing strings. When calling Contains (), I would like a case insensitive comparison. (I don't want to add newfile.txt to a Listbox containing NewFile.txt). I'm considering writing a CaseInsensitiveString class which would contain a string, and which would do a case insensitive comparison, but I'm wondering if there's an easier way.
1
1925
by: Rasika Wijayaratne | last post by:
Hello, Can I get feedback on these .NET coding best practices please. Thanks to Konrad Rudolph and Jon Skeet for the replies to my previous post on 'Writing Properties.' Thanks in advance to all replies to this post as well, as I am having probs posting from MS Communities site (posting from Google). =========== Avoid Returning null Instead of Array, String, or Collection
5
3832
by: Gerrit Beuze | last post by:
Hi all, Using C# 1.1: I need a fast way of determining whether a string is in a list of approx 150 keyword like strings. in two versions: one case-sensitive, the other one case-insenstive. I thought of loading the keywords in a Hastable as Keys with null values, and then use Hastable.ContainsKey(string) but Hashtable does not seem to support case-insentive keys.
1
3699
by: Raterus | last post by:
Howdy, I'm making a search engine for an application I'm working on. I want to "bold" keywords they have searched for. I have a long string of words that represents a particular document, and I need to find out how to do a replace on this string, but have it be case-insensitive. For instance: dim docWords as string = "BLAH blah BlaH!" dim myString as string = "blah" docWords = docWords.Replace(myString, "<b>" & myString & "</b>") ...
3
1630
by: kd | last post by:
Hi All, How to perform case-insensitive comparision of strings? Would there be some kind of an indicator, which when set to true, would allow case-insenitive comparision of strings using if/select case, etc; after performing the case-insenisitive compare, the indicator can be reset to allow the conventional comparision of strings? kd
7
3325
by: Adrian | last post by:
Hi, I want a const static std::set of strings which is case insensitive for the values. So I have the following which seems to work but something doesnt seem right about it. Is there a better way or any gotcha's from my code below.
4
2579
hsriat
by: hsriat | last post by:
function repAll(t) { var finds = new Array(......); //array of to-be-replaced strings var repls = new Array(......); //array of replace-with strings t = t.replace(finds, repls, 'gi'); } Working fine with FF, but not with IE, Opera and Safari... How can I solve this?
0
7971
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7893
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
6698
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5847
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5436
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3889
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3932
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2408
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1243
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.