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. Web Development
  3. ASP.NET
  4. how to compare whetther a substring is available in striong or not

how to compare whetther a substring is available in striong or not

Scheduled Pinned Locked Moved ASP.NET
tutorialquestion
11 Posts 7 Posters 1 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.
  • A Offline
    A Offline
    Amit Agarrwal
    wrote on last edited by
    #1

    exactly waht i want to do i want to check that whether a particular string is in the string or not? like str ="C:\Inetpub\wwwroot\medicaps"; now i want ot check whether a wwwroot is in this string or not. thanx

    B N R 3 Replies Last reply
    0
    • A Amit Agarrwal

      exactly waht i want to do i want to check that whether a particular string is in the string or not? like str ="C:\Inetpub\wwwroot\medicaps"; now i want ot check whether a wwwroot is in this string or not. thanx

      B Offline
      B Offline
      BLOEDHOND
      wrote on last edited by
      #2

      I know C++ had a string compare function, If if available in .Net dont know

      1 Reply Last reply
      0
      • A Amit Agarrwal

        exactly waht i want to do i want to check that whether a particular string is in the string or not? like str ="C:\Inetpub\wwwroot\medicaps"; now i want ot check whether a wwwroot is in this string or not. thanx

        N Offline
        N Offline
        Not Active
        wrote on last edited by
        #3

        Perhaps you would like to listen to the advice given on your last post before asking the same question again. X| :rolleyes:


        only two letters away from being an asset

        1 Reply Last reply
        0
        • A Amit Agarrwal

          exactly waht i want to do i want to check that whether a particular string is in the string or not? like str ="C:\Inetpub\wwwroot\medicaps"; now i want ot check whether a wwwroot is in this string or not. thanx

          R Offline
          R Offline
          Ramasubramaniam
          wrote on last edited by
          #4

          Hi here is the way, we can use "IndexOf" string class method. string strTest = "I am strong"; if(strTest.IndexOf("strong")==0) { return(false); } Ram

          J 1 Reply Last reply
          0
          • R Ramasubramaniam

            Hi here is the way, we can use "IndexOf" string class method. string strTest = "I am strong"; if(strTest.IndexOf("strong")==0) { return(false); } Ram

            J Offline
            J Offline
            Jason Weibel
            wrote on last edited by
            #5

            Using IndexOf will work but the System.Text.RegularExpressions is a better way, here is an example. Private Function InLine(ByVal Line As String, ByVal Value As String) As Boolean   Dim r As Regex = New Regex(Value, RegexOptions.IgnoreCase)   Dim m As Match = r.Match(Line)   If m.Success Then Return True Else Return False End Function

            Jason

            E G 2 Replies Last reply
            0
            • J Jason Weibel

              Using IndexOf will work but the System.Text.RegularExpressions is a better way, here is an example. Private Function InLine(ByVal Line As String, ByVal Value As String) As Boolean   Dim r As Regex = New Regex(Value, RegexOptions.IgnoreCase)   Dim m As Match = r.Match(Line)   If m.Success Then Return True Else Return False End Function

              Jason

              E Offline
              E Offline
              eggsovereasy
              wrote on last edited by
              #6

              Why not just use .Contains()?

              J 1 Reply Last reply
              0
              • E eggsovereasy

                Why not just use .Contains()?

                J Offline
                J Offline
                Jason Weibel
                wrote on last edited by
                #7

                To the best of my knowledge .Contains is not available to string variables. It is for ArrayList and other Collection objects. If this is wrong could you please show me an example?

                Jason

                E 1 Reply Last reply
                0
                • J Jason Weibel

                  To the best of my knowledge .Contains is not available to string variables. It is for ArrayList and other Collection objects. If this is wrong could you please show me an example?

                  Jason

                  E Offline
                  E Offline
                  eggsovereasy
                  wrote on last edited by
                  #8

                  string.Contains

                  G 1 Reply Last reply
                  0
                  • E eggsovereasy

                    string.Contains

                    G Offline
                    G Offline
                    Guffa
                    wrote on last edited by
                    #9

                    Will do nicely. It's only available in framework 2.x.

                    --- b { font-weight: normal; }

                    1 Reply Last reply
                    0
                    • J Jason Weibel

                      Using IndexOf will work but the System.Text.RegularExpressions is a better way, here is an example. Private Function InLine(ByVal Line As String, ByVal Value As String) As Boolean   Dim r As Regex = New Regex(Value, RegexOptions.IgnoreCase)   Dim m As Match = r.Match(Line)   If m.Success Then Return True Else Return False End Function

                      Jason

                      G Offline
                      G Offline
                      Guffa
                      wrote on last edited by
                      #10

                      If you need the added functionality that the regular expression offers, it's a better way. If you don't, the IndexOf way is more efficient. You forgot to escape the value, by the way. And I really don't see the reason to check the value of Success before returning it... ;)

                      Private Function InLine(ByVal Line As String, ByVal Value As String) As Boolean
                      Dim r As Regex = New Regex(Regex.Escape(Value), RegexOptions.IgnoreCase)
                      Dim m As Match = r.Match(Line)
                      Return m.Success
                      End Function

                      --- b { font-weight: normal; }

                      J 1 Reply Last reply
                      0
                      • G Guffa

                        If you need the added functionality that the regular expression offers, it's a better way. If you don't, the IndexOf way is more efficient. You forgot to escape the value, by the way. And I really don't see the reason to check the value of Success before returning it... ;)

                        Private Function InLine(ByVal Line As String, ByVal Value As String) As Boolean
                        Dim r As Regex = New Regex(Regex.Escape(Value), RegexOptions.IgnoreCase)
                        Dim m As Match = r.Match(Line)
                        Return m.Success
                        End Function

                        --- b { font-weight: normal; }

                        J Offline
                        J Offline
                        Jason Weibel
                        wrote on last edited by
                        #11

                        I'm still working with 1.1 so that is good to know when I move to 2.0 – thank you. I see your point with using the IndexOf and agree it will provide better performance then the function.

                        Jason

                        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