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. C#
  4. string.split question

string.split question

Scheduled Pinned Locked Moved C#
questionhelptutorial
5 Posts 5 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.
  • J Offline
    J Offline
    jashimu
    wrote on last edited by
    #1

    hi All, I am having trouble doing some string manipulation. I get a string with coma delimited. I want remove the first portion of the string. for example,strMessage = " I, Have, a, string, that, describe, something" what I want to do is that remove the first coma delimited part of the variable strMessage so it look like this "Have, a, string, that, describe, something" how do I do this. Any help appreciated. then I insert the string in my datagridview.

    datagridview.Rows.Insert(0,strMessage.Split(','))

    I want to keep this style of inserting into dataGridView just want to remove the first portion of the string which is "I". thanks

    L D D realJSOPR 4 Replies Last reply
    0
    • J jashimu

      hi All, I am having trouble doing some string manipulation. I get a string with coma delimited. I want remove the first portion of the string. for example,strMessage = " I, Have, a, string, that, describe, something" what I want to do is that remove the first coma delimited part of the variable strMessage so it look like this "Have, a, string, that, describe, something" how do I do this. Any help appreciated. then I insert the string in my datagridview.

      datagridview.Rows.Insert(0,strMessage.Split(','))

      I want to keep this style of inserting into dataGridView just want to remove the first portion of the string which is "I". thanks

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      string.Split() is the method you want; it has a few overloads, so I refer to its documentation. BTW: you won't solve problems any faster by putting as much as possible into a single statement. Split things up, and look at the intermediate values while debugging. :)

      Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

      1 Reply Last reply
      0
      • J jashimu

        hi All, I am having trouble doing some string manipulation. I get a string with coma delimited. I want remove the first portion of the string. for example,strMessage = " I, Have, a, string, that, describe, something" what I want to do is that remove the first coma delimited part of the variable strMessage so it look like this "Have, a, string, that, describe, something" how do I do this. Any help appreciated. then I insert the string in my datagridview.

        datagridview.Rows.Insert(0,strMessage.Split(','))

        I want to keep this style of inserting into dataGridView just want to remove the first portion of the string which is "I". thanks

        D Offline
        D Offline
        Dan Mos
        wrote on last edited by
        #3

        this is quite simple for the case you stated. That is just the first comma. Use IndexOf. Something like:

        str.Substring(str.IndexOf(",") + 1).TrimStart();//the TrimStart eliminates the white space after the "I,"

        All the best, Dan

        1 Reply Last reply
        0
        • J jashimu

          hi All, I am having trouble doing some string manipulation. I get a string with coma delimited. I want remove the first portion of the string. for example,strMessage = " I, Have, a, string, that, describe, something" what I want to do is that remove the first coma delimited part of the variable strMessage so it look like this "Have, a, string, that, describe, something" how do I do this. Any help appreciated. then I insert the string in my datagridview.

          datagridview.Rows.Insert(0,strMessage.Split(','))

          I want to keep this style of inserting into dataGridView just want to remove the first portion of the string which is "I". thanks

          D Offline
          D Offline
          Dalek Dave
          wrote on last edited by
          #4

          Here[^] is the solution to all your problems. (Well the ones about splitting, personal probelms are chargeable).

          ------------------------------------ I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave CCC Link[^] Trolls[^]

          1 Reply Last reply
          0
          • J jashimu

            hi All, I am having trouble doing some string manipulation. I get a string with coma delimited. I want remove the first portion of the string. for example,strMessage = " I, Have, a, string, that, describe, something" what I want to do is that remove the first coma delimited part of the variable strMessage so it look like this "Have, a, string, that, describe, something" how do I do this. Any help appreciated. then I insert the string in my datagridview.

            datagridview.Rows.Insert(0,strMessage.Split(','))

            I want to keep this style of inserting into dataGridView just want to remove the first portion of the string which is "I". thanks

            realJSOPR Offline
            realJSOPR Offline
            realJSOP
            wrote on last edited by
            #5

            string[] parts = strMessage.Split(",");
            for (int i = 0; i < parts.Length; i++)
            {
            parts[i] = parts[i].Trim();
            }
            dataGridView.Rows.Insert(0, parts);

            But don't you need to ensure that the number of parts matches the number of columns you have in the row?

            ".45 ACP - because shooting twice is just silly" - JSOP, 2010
            -----
            You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
            -----
            "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

            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