[Solved] A strange question about strings. [modified]
-
Hi all, I need that application I'm developing can consider the same (=), 3 strings for example like these: String A = "This, is, a, sample, 12345" String B = "this, is,a, Sample ,12345" String C = "This,is,a,sample,12345" Someone know if there is a simple way (may be a single instruction?) to do that? I know how to do that, but it is not a simple way. Thanks Ignazio
modified on Saturday, September 12, 2009 2:09 PM
-
Hi all, I need that application I'm developing can consider the same (=), 3 strings for example like these: String A = "This, is, a, sample, 12345" String B = "this, is,a, Sample ,12345" String C = "This,is,a,sample,12345" Someone know if there is a simple way (may be a single instruction?) to do that? I know how to do that, but it is not a simple way. Thanks Ignazio
modified on Saturday, September 12, 2009 2:09 PM
your question is unclear. IF what you want is a way to compare two strings ignoring white space, ignoring comma's and ignoring case, then the solution is two write a function
MyStringCompare(ByVal string1 as String, ByVal string2 as String) as Integer
wherein you first remove white space and comma's, and then use the built-in string compare function, telling it to ignore case. If that is unclear to you, I strongly advice you to buy and study a book on the programming language of your choice. :)Luc Pattyn
:badger: :jig: :badger:
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
:jig: :badger: :jig:
-
Hi all, I need that application I'm developing can consider the same (=), 3 strings for example like these: String A = "This, is, a, sample, 12345" String B = "this, is,a, Sample ,12345" String C = "This,is,a,sample,12345" Someone know if there is a simple way (may be a single instruction?) to do that? I know how to do that, but it is not a simple way. Thanks Ignazio
modified on Saturday, September 12, 2009 2:09 PM
can you explain it little more what is your point if i am not wrong do you want that you have same string but in different cases and spaces and you want it to be consider as same is this your question or what ????
Best Of Regards, SOFTDEV Sad like books with torn pages, sad like unfinished stories ...
-
your question is unclear. IF what you want is a way to compare two strings ignoring white space, ignoring comma's and ignoring case, then the solution is two write a function
MyStringCompare(ByVal string1 as String, ByVal string2 as String) as Integer
wherein you first remove white space and comma's, and then use the built-in string compare function, telling it to ignore case. If that is unclear to you, I strongly advice you to buy and study a book on the programming language of your choice. :)Luc Pattyn
:badger: :jig: :badger:
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
:jig: :badger: :jig:
Hi, Yes, I need a way to compare 2 strings, ignoring spaces and case. In the end of my question, I written that I know how to do that, but I was hoping that someone know a simpler way, or may be an already built-in instruction in V.B. to do this work. Thanks for help and for "advice" Ignazio
-
can you explain it little more what is your point if i am not wrong do you want that you have same string but in different cases and spaces and you want it to be consider as same is this your question or what ????
Best Of Regards, SOFTDEV Sad like books with torn pages, sad like unfinished stories ...
Hi, Yes.
-
Hi all, I need that application I'm developing can consider the same (=), 3 strings for example like these: String A = "This, is, a, sample, 12345" String B = "this, is,a, Sample ,12345" String C = "This,is,a,sample,12345" Someone know if there is a simple way (may be a single instruction?) to do that? I know how to do that, but it is not a simple way. Thanks Ignazio
modified on Saturday, September 12, 2009 2:09 PM
You can do a case insensitive comparison easy enough. I don't know there's a way to ignore spaces without actually removing them. String.Compare takes a bool to say if it's case sensitive.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
You can do a case insensitive comparison easy enough. I don't know there's a way to ignore spaces without actually removing them. String.Compare takes a bool to say if it's case sensitive.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
That for me has prioritary importance, is the problem of spaces. The case insensitive comparation is a secondary requirement. It seems that I can't avoid the work to delete spaces....... Ignazio
-
That for me has prioritary importance, is the problem of spaces. The case insensitive comparation is a secondary requirement. It seems that I can't avoid the work to delete spaces....... Ignazio
No, because you're creating an odd definition of 'equal'. You may be able to use regex to create a string that allows arbitrary spaces between each character, but it seems like more work than just stripping them, to me.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
No, because you're creating an odd definition of 'equal'. You may be able to use regex to create a string that allows arbitrary spaces between each character, but it seems like more work than just stripping them, to me.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
Thanks for help, I will evaluate what is more convenient to do. Strings that I must compare can have until 23 commas! Ignazio
-
That for me has prioritary importance, is the problem of spaces. The case insensitive comparation is a secondary requirement. It seems that I can't avoid the work to delete spaces....... Ignazio
hope so this will work , I did this thing for you but MVPs don't recommend this because copy paste will not enhance your programing skills
Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim str1, str2 As String str1 = "softdev\_sup" str2 = "Softdev\_ sup" MessageBox.Show(String.Compare(str1, str2, False)) MessageBox.Show(String.Compare(RemoveSpace(str1), RemoveSpace(str2), True)) End Sub Public Function RemoveSpace(ByVal strText As String) As String Return System.Text.RegularExpressions.Regex.Replace(strText, " ", \_ String.Empty, System.Text.RegularExpressions.RegexOptions.IgnoreCase) End Function
Best Of Regards, SOFTDEV Sad like books with torn pages, sad like unfinished stories ...
-
hope so this will work , I did this thing for you but MVPs don't recommend this because copy paste will not enhance your programing skills
Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim str1, str2 As String str1 = "softdev\_sup" str2 = "Softdev\_ sup" MessageBox.Show(String.Compare(str1, str2, False)) MessageBox.Show(String.Compare(RemoveSpace(str1), RemoveSpace(str2), True)) End Sub Public Function RemoveSpace(ByVal strText As String) As String Return System.Text.RegularExpressions.Regex.Replace(strText, " ", \_ String.Empty, System.Text.RegularExpressions.RegexOptions.IgnoreCase) End Function
Best Of Regards, SOFTDEV Sad like books with torn pages, sad like unfinished stories ...
Hi, The code you posted seems to be exactely that I was looking for. With great surprise, differentely I was thinking, it is also fully compliant with Compact Framework, without any modification. Running the code, the first message is "1" and second is "0". To reduce the impact on the programing skills, I will do the work in 2 steps: A first pass will exclude strings 100% equal (considering also spaces), from the 2nd pass that will compare only remaining strings using the RemoveSpace function. Thank you very much. Ignazio
modified on Monday, September 7, 2009 12:44 PM
-
Hi, The code you posted seems to be exactely that I was looking for. With great surprise, differentely I was thinking, it is also fully compliant with Compact Framework, without any modification. Running the code, the first message is "1" and second is "0". To reduce the impact on the programing skills, I will do the work in 2 steps: A first pass will exclude strings 100% equal (considering also spaces), from the 2nd pass that will compare only remaining strings using the RemoveSpace function. Thank you very much. Ignazio
modified on Monday, September 7, 2009 12:44 PM