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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. split the string and check it to another string

split the string and check it to another string

Scheduled Pinned Locked Moved ASP.NET
tutorial
7 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.
  • M Offline
    M Offline
    Member 3879881
    wrote on last edited by
    #1

    Hi i have a string like this: string lgtext=text5,text2,text6,text4; now i have another string : string shtext= text2; now the lgtext contained that second string(shtext) or not have to test..., how to split and execute it..,.

    Thanks & Regards, Member 3879881, please don't forget to vote on the post

    P D 2 Replies Last reply
    0
    • M Member 3879881

      Hi i have a string like this: string lgtext=text5,text2,text6,text4; now i have another string : string shtext= text2; now the lgtext contained that second string(shtext) or not have to test..., how to split and execute it..,.

      Thanks & Regards, Member 3879881, please don't forget to vote on the post

      P Offline
      P Offline
      padmanabhan N
      wrote on last edited by
      #2

      here: protected void Button1_Click(object sender, EventArgs e) { string lgtext = "text5, text2, text6, text4"; string shtext = "text2"; string[] split = lgtext.Split(','); for(int i=0;i< =split.Length-1;i++) { if (split[i].Trim() == shtext) Response.Write("Found"); } }

      Padmanabhan My Articles[^]

      M 1 Reply Last reply
      0
      • P padmanabhan N

        here: protected void Button1_Click(object sender, EventArgs e) { string lgtext = "text5, text2, text6, text4"; string shtext = "text2"; string[] split = lgtext.Split(','); for(int i=0;i< =split.Length-1;i++) { if (split[i].Trim() == shtext) Response.Write("Found"); } }

        Padmanabhan My Articles[^]

        M Offline
        M Offline
        Member 3879881
        wrote on last edited by
        #3

        Hi padmanabhan thanks for ur reply..., we can use this following method it will work fine? if(lgtext.indexof(shtext)!=-1) { 'found' } else { 'not found' } is't ok?

        Thanks & Regards, Member 3879881, please don't forget to vote on the post

        1 Reply Last reply
        0
        • M Member 3879881

          Hi i have a string like this: string lgtext=text5,text2,text6,text4; now i have another string : string shtext= text2; now the lgtext contained that second string(shtext) or not have to test..., how to split and execute it..,.

          Thanks & Regards, Member 3879881, please don't forget to vote on the post

          D Offline
          D Offline
          dan sh
          wrote on last edited by
          #4

          Why would you even split this? String class has Contains method. Use it.

          P C 2 Replies Last reply
          0
          • D dan sh

            Why would you even split this? String class has Contains method. Use it.

            P Offline
            P Offline
            padmanabhan N
            wrote on last edited by
            #5

            d@nish wrote:

            String class has Contains method. Use it.

            contains method won't give exact search.. eg., string search = text1,text2,text3,text4; if we want to search for "text" in this, by using contains will give found message for all the condition. But my output must be exactly "text" which is not present in the string. so, for most of the requirements contains wont provide exact result.

            Padmanabhan My Articles[^]

            D 1 Reply Last reply
            0
            • P padmanabhan N

              d@nish wrote:

              String class has Contains method. Use it.

              contains method won't give exact search.. eg., string search = text1,text2,text3,text4; if we want to search for "text" in this, by using contains will give found message for all the condition. But my output must be exactly "text" which is not present in the string. so, for most of the requirements contains wont provide exact result.

              Padmanabhan My Articles[^]

              D Offline
              D Offline
              dan sh
              wrote on last edited by
              #6

              Agreed. Provided the string structure remains same, check for the trailing comma as well after the text to match. This would work.

              1 Reply Last reply
              0
              • D dan sh

                Why would you even split this? String class has Contains method. Use it.

                C Offline
                C Offline
                Chetan visodiya
                wrote on last edited by
                #7

                This will not work for below string string lgtext = "text5, text2, text6, text4, text7text8 "; And you have find exact "text8". if you use Contains then it returns true but text8 is not in the collection. So better to use below code. protected void Button1_Click(object sender, EventArgs e) { string lgtext = "text5, text2, text6, text4"; string shtext = "text2"; string[] split = lgtext.Split(','); for(int i=0;i&lt; =split.Length-1;i++) { if(split[i].Contains(shtext)) Response.Write("Found"); } }

                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