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. Delimiters - Is there a simple way

Delimiters - Is there a simple way

Scheduled Pinned Locked Moved C#
helpquestion
12 Posts 6 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.
  • P Paul Conrad

    You may want to try regular expressions...


    "too much daily WTF for someone..." - Anton Afanasyev

    H Offline
    H Offline
    haz13
    wrote on last edited by
    #3

    Sorry Paul what do you mean by regular expressions? I'm only fairly new to this c#

    Haz

    G P 2 Replies Last reply
    0
    • H haz13

      Sorry Paul what do you mean by regular expressions? I'm only fairly new to this c#

      Haz

      P Offline
      P Offline
      Paul Conrad
      wrote on last edited by
      #4

      haz13 wrote:

      what do you mean by regular expressions? I'm only fairly new to this c#

      Being new is cool. Regular expressions are a finite state automaton that work with search patterns, etc. Take a look at this article: Expresso[^]


      "too much daily WTF for someone..." - Anton Afanasyev

      H 1 Reply Last reply
      0
      • H haz13

        Sorry Paul what do you mean by regular expressions? I'm only fairly new to this c#

        Haz

        G Offline
        G Offline
        Giorgi Dalakishvili
        wrote on last edited by
        #5

        haz13 wrote:

        what do you mean by regular expressions?

        Here: http://en.wikipedia.org/wiki/Regular_expression[^] http://www.regular-expressions.info/[^]

        #region signature my articles #endregion

        P 1 Reply Last reply
        0
        • P Paul Conrad

          haz13 wrote:

          what do you mean by regular expressions? I'm only fairly new to this c#

          Being new is cool. Regular expressions are a finite state automaton that work with search patterns, etc. Take a look at this article: Expresso[^]


          "too much daily WTF for someone..." - Anton Afanasyev

          H Offline
          H Offline
          haz13
          wrote on last edited by
          #6

          Thanks for that info guys, I'll go away and have a read up on it :)

          Haz

          1 Reply Last reply
          0
          • G Giorgi Dalakishvili

            haz13 wrote:

            what do you mean by regular expressions?

            Here: http://en.wikipedia.org/wiki/Regular_expression[^] http://www.regular-expressions.info/[^]

            #region signature my articles #endregion

            P Offline
            P Offline
            Paul Conrad
            wrote on last edited by
            #7

            Giorgi Dalakishvili wrote:

            http://www.regular-expressions.info/\[

            That looks like a bookmark worthy site to me :-D


            "too much daily WTF for someone..." - Anton Afanasyev

            1 Reply Last reply
            0
            • H haz13

              I have a text file of the following format "apple","orange","pear" etc I have tried both char and string seperators but can't think of a way grab the data cleanly without including a " or , . I either end up with "apple" "orange" "pear" or "apple orange pear" The code I have been using. private static char[] charSeperator = new char[] { ',' }; private static string[] strSeperator = new string[] {"\",\""}; strArray = strLine.Split(charSeperator); strArray = strLine.Split(strSeperator,StringSplitOptions.None); Is there a simple way of grabing apple orange and pear from the text file, without having to do further data cleaning? Thanks in advance for any help you can offer

              Haz

              J Offline
              J Offline
              jblouir
              wrote on last edited by
              #8

              using System.Text.RegularExpressions; // the namespace for using Substring strArray = strLine.Split(new char[] { ',' }; // Use this still, but with the modifications below foreach (string fruit in strArray) // a loop that runs for every piece of fruit in strArray { int fruitlength = fruit.Length; // getting the length of the fruit string fruitlength = fruitlength - 2; // subtracting 2 because of quotes string trimmedfruit = fruit; trimmedfruit = fruit.Substring(1,fruitlength); // basically the method Substring(start,length) // and the first letter starts at 0 and length is how many you want to cut out // so I took the total length of string "apple", subtracted 2 because of quotes // then started the trim at 1 just after the first qoute and pulled out all the letters // minus the qoutes }

              C 1 Reply Last reply
              0
              • J jblouir

                using System.Text.RegularExpressions; // the namespace for using Substring strArray = strLine.Split(new char[] { ',' }; // Use this still, but with the modifications below foreach (string fruit in strArray) // a loop that runs for every piece of fruit in strArray { int fruitlength = fruit.Length; // getting the length of the fruit string fruitlength = fruitlength - 2; // subtracting 2 because of quotes string trimmedfruit = fruit; trimmedfruit = fruit.Substring(1,fruitlength); // basically the method Substring(start,length) // and the first letter starts at 0 and length is how many you want to cut out // so I took the total length of string "apple", subtracted 2 because of quotes // then started the trim at 1 just after the first qoute and pulled out all the letters // minus the qoutes }

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

                jblouir wrote:

                using System.Text.RegularExpressions; // the namespace for using Substring

                Sorry, but, what are you thinking ? Substring is a method on a class, you don't need a namespace to call it. string trimmedFruit = fruit.Replace("\"", ""); is even easier.

                Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

                J 1 Reply Last reply
                0
                • C Christian Graus

                  jblouir wrote:

                  using System.Text.RegularExpressions; // the namespace for using Substring

                  Sorry, but, what are you thinking ? Substring is a method on a class, you don't need a namespace to call it. string trimmedFruit = fruit.Replace("\"", ""); is even easier.

                  Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

                  J Offline
                  J Offline
                  jblouir
                  wrote on last edited by
                  #10

                  Your right, didn't realise. Still learning, on week 1 and a half now. At the point when I was learning how to use regular expressions I must have stumbled on to substring and assumed it was part of the namespace. and I didn't know replace even existed

                  J 1 Reply Last reply
                  0
                  • J jblouir

                    Your right, didn't realise. Still learning, on week 1 and a half now. At the point when I was learning how to use regular expressions I must have stumbled on to substring and assumed it was part of the namespace. and I didn't know replace even existed

                    J Offline
                    J Offline
                    jblouir
                    wrote on last edited by
                    #11

                    If you didnt understand his code above. string trimmedFruit = fruit.Replace("\"", ""); its basically a \" in there so every " it finds it replaces it with "" // e.g. null using the \ allows you to put a " in the string text

                    1 Reply Last reply
                    0
                    • H haz13

                      I have a text file of the following format "apple","orange","pear" etc I have tried both char and string seperators but can't think of a way grab the data cleanly without including a " or , . I either end up with "apple" "orange" "pear" or "apple orange pear" The code I have been using. private static char[] charSeperator = new char[] { ',' }; private static string[] strSeperator = new string[] {"\",\""}; strArray = strLine.Split(charSeperator); strArray = strLine.Split(strSeperator,StringSplitOptions.None); Is there a simple way of grabing apple orange and pear from the text file, without having to do further data cleaning? Thanks in advance for any help you can offer

                      Haz

                      L Offline
                      L Offline
                      Life as a Coder
                      wrote on last edited by
                      #12

                      haz13 wrote:

                      I have tried both char and string separators but can't think of a way grab the data cleanly without including a " or , . I either end up with "apple" "orange" "pear" or "apple orange pear"

                      I used similar code to split it. Heres some code, maybe it can help u. Input text same as u : "apple","orange","pear" etc assume the string named "str"

                      string[] strArray = str.split(',');
                      for (int i=0;i

                      Training makes perfect....

                      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