Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. [Solved] A strange question about strings. [modified]

[Solved] A strange question about strings. [modified]

Scheduled Pinned Locked Moved Visual Basic
tutorialquestion
12 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Hurricane3000

    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

    I Offline
    I Offline
    i i i
    wrote on last edited by
    #3

    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 ...

    H 1 Reply Last reply
    0
    • L Luc Pattyn

      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:

      H Offline
      H Offline
      Hurricane3000
      wrote on last edited by
      #4

      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

      1 Reply Last reply
      0
      • I i i i

        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 ...

        H Offline
        H Offline
        Hurricane3000
        wrote on last edited by
        #5

        Hi, Yes.

        1 Reply Last reply
        0
        • H Hurricane3000

          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

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #6

          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.

          H 1 Reply Last reply
          0
          • C Christian Graus

            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.

            H Offline
            H Offline
            Hurricane3000
            wrote on last edited by
            #7

            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

            C I 2 Replies Last reply
            0
            • H Hurricane3000

              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

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #8

              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.

              H 1 Reply Last reply
              0
              • C Christian Graus

                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.

                H Offline
                H Offline
                Hurricane3000
                wrote on last edited by
                #9

                Thanks for help, I will evaluate what is more convenient to do. Strings that I must compare can have until 23 commas! Ignazio

                1 Reply Last reply
                0
                • H Hurricane3000

                  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

                  I Offline
                  I Offline
                  i i i
                  wrote on last edited by
                  #10

                  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 ...

                  H 1 Reply Last reply
                  0
                  • I i i i

                    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 ...

                    H Offline
                    H Offline
                    Hurricane3000
                    wrote on last edited by
                    #11

                    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

                    I 1 Reply Last reply
                    0
                    • H Hurricane3000

                      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

                      I Offline
                      I Offline
                      i i i
                      wrote on last edited by
                      #12

                      :-D u r welcome man say thanks 2 code project

                      Best Of Regards, SOFTDEV Sad like books with torn pages, sad like unfinished stories ...

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups