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. getting substring from a string

getting substring from a string

Scheduled Pinned Locked Moved C#
helpbeta-testingquestion
14 Posts 3 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 Manas Bhardwaj

    Here you go : String fixString = "Whateever"; string[] fixArray = fixString.Split(Convert.ToChar(1)); //I used 1 because FIX message uses this as delimiter... HashTable fixTable = new HashTable(); string[] fieldArray = null; for (int fieldCount = 1; fieldCount < message.Length; fieldCount++) { fieldArray = fixArray[fieldCount].Split('='); fixTable.Add(fieldArray[0].ToString(), fieldArray[1].ToString()); } Hope this helps. by the way, I too used all this in my early carrier. ;)

    A Offline
    A Offline
    Ankit Aneja
    wrote on last edited by
    #4

    if i am able to do it like this 100=ARCA10=169|0| using substring now i have to get value of first tag eg 100= Result should be "ARCA" i want it in seperate string

    Ankit Aneja "Nothing is impossible. The word itself says - I M possible"

    M 1 Reply Last reply
    0
    • A Ankit Aneja

      if i am able to do it like this 100=ARCA10=169|0| using substring now i have to get value of first tag eg 100= Result should be "ARCA" i want it in seperate string

      Ankit Aneja "Nothing is impossible. The word itself says - I M possible"

      M Offline
      M Offline
      Manas Bhardwaj
      wrote on last edited by
      #5

      String fixString = "Whateever"; string[] fixArray = fixString.Split(Convert.ToChar(1)); //I used 1 because FIX message uses this as delimiter... HashTable fixTable = new HashTable(); string[] fieldArray = null; for (int fieldCount = 1; fieldCount < message.Length; fieldCount++) { fieldArray = fixArray[fieldCount].Split('='); fixTable.Add(fieldArray[0].ToString(), fieldArray[1].ToString()); } string firstTagString = fixTable["100"].ToString() This will give you string which is there in tag 100, no matter at what position it is at. I am telling you this because FIX is a tag based protocol and not a position based. The position may vary from message to message. It is a more generalized solution for your scenario. Success

      A 1 Reply Last reply
      0
      • M Manas Bhardwaj

        String fixString = "Whateever"; string[] fixArray = fixString.Split(Convert.ToChar(1)); //I used 1 because FIX message uses this as delimiter... HashTable fixTable = new HashTable(); string[] fieldArray = null; for (int fieldCount = 1; fieldCount < message.Length; fieldCount++) { fieldArray = fixArray[fieldCount].Split('='); fixTable.Add(fieldArray[0].ToString(), fieldArray[1].ToString()); } string firstTagString = fixTable["100"].ToString() This will give you string which is there in tag 100, no matter at what position it is at. I am telling you this because FIX is a tag based protocol and not a position based. The position may vary from message to message. It is a more generalized solution for your scenario. Success

        A Offline
        A Offline
        Ankit Aneja
        wrote on last edited by
        #6

        you do message.Length you mean fixString.Length here Am i right even than its crashing for my message

        Ankit Aneja "Nothing is impossible. The word itself says - I M possible"

        M 1 Reply Last reply
        0
        • A Ankit Aneja

          you do message.Length you mean fixString.Length here Am i right even than its crashing for my message

          Ankit Aneja "Nothing is impossible. The word itself says - I M possible"

          M Offline
          M Offline
          Manas Bhardwaj
          wrote on last edited by
          #7

          My Mistake :omg: It should be fixArray Here's your code String fixString = "Whateever"; string[] fixArray = fixString.Split(Convert.ToChar(1)); //I used 1 because FIX message uses this as delimiter... HashTable fixTable = new HashTable(); string[] fieldArray = null; for (int fieldCount = 1; fieldCount < fixArray.Length; fieldCount++) { fieldArray = fixArray[fieldCount].Split('='); fixTable.Add(fieldArray[0].ToString(), fieldArray[1].ToString()); } string firstTagString = fixTable["100"].ToString()

          A 1 Reply Last reply
          0
          • M Manas Bhardwaj

            My Mistake :omg: It should be fixArray Here's your code String fixString = "Whateever"; string[] fixArray = fixString.Split(Convert.ToChar(1)); //I used 1 because FIX message uses this as delimiter... HashTable fixTable = new HashTable(); string[] fieldArray = null; for (int fieldCount = 1; fieldCount < fixArray.Length; fieldCount++) { fieldArray = fixArray[fieldCount].Split('='); fixTable.Add(fieldArray[0].ToString(), fieldArray[1].ToString()); } string firstTagString = fixTable["100"].ToString()

            A Offline
            A Offline
            Ankit Aneja
            wrote on last edited by
            #8

            its still giving index was outside the bounds of array

            Ankit Aneja "Nothing is impossible. The word itself says - I M possible"

            M 1 Reply Last reply
            0
            • A Ankit Aneja

              its still giving index was outside the bounds of array

              Ankit Aneja "Nothing is impossible. The word itself says - I M possible"

              M Offline
              M Offline
              Manas Bhardwaj
              wrote on last edited by
              #9

              Can you post your code here? Also provide the string which you using

              A 1 Reply Last reply
              0
              • M Manas Bhardwaj

                Can you post your code here? Also provide the string which you using

                A Offline
                A Offline
                Ankit Aneja
                wrote on last edited by
                #10

                try { String fixString = newLine; string[] fixArray = fixString.Split(Convert.ToChar(1)); //I used 1 because FIX message uses this as delimiter... Hashtable fixTable = new Hashtable(); string[] fieldArray = null; for (int fieldCount = 1; fieldCount < fixArray.Length; fieldCount++) { fieldArray = fixArray[fieldCount].Split('='); fixTable.Add(fieldArray[0].ToString(), fieldArray[1].ToString()); } string firstTagString = fixTable["100"].ToString(); } catch(Exception ex) { String x=ex.ToString(); } "M|2696|0|D|I|20070604-19:31:25.177|255|8=FIX.4.29=23235=D34=269649=Qa-QTIP-Sim-A56=Qa-QTIP-Sim-A-Internal52=20070604-23:31:2540=1MDSNAPID=6071=511=Q8BO7023-121=4955=QQQQ59=05011=12463/2007-06-04-07:3138=100109=RajTest5012=Raj9040=NSTRATEGY=PassThru54=147=A100=ARCA10=169|0|\r"

                Ankit Aneja "Nothing is impossible. The word itself says - I M possible"

                M 1 Reply Last reply
                0
                • A Ankit Aneja

                  try { String fixString = newLine; string[] fixArray = fixString.Split(Convert.ToChar(1)); //I used 1 because FIX message uses this as delimiter... Hashtable fixTable = new Hashtable(); string[] fieldArray = null; for (int fieldCount = 1; fieldCount < fixArray.Length; fieldCount++) { fieldArray = fixArray[fieldCount].Split('='); fixTable.Add(fieldArray[0].ToString(), fieldArray[1].ToString()); } string firstTagString = fixTable["100"].ToString(); } catch(Exception ex) { String x=ex.ToString(); } "M|2696|0|D|I|20070604-19:31:25.177|255|8=FIX.4.29=23235=D34=269649=Qa-QTIP-Sim-A56=Qa-QTIP-Sim-A-Internal52=20070604-23:31:2540=1MDSNAPID=6071=511=Q8BO7023-121=4955=QQQQ59=05011=12463/2007-06-04-07:3138=100109=RajTest5012=Raj9040=NSTRATEGY=PassThru54=147=A100=ARCA10=169|0|\r"

                  Ankit Aneja "Nothing is impossible. The word itself says - I M possible"

                  M Offline
                  M Offline
                  Manas Bhardwaj
                  wrote on last edited by
                  #11

                  Here it is: try { string newLine = "M|2696|0|D|I|20070604-19:31:25.177|255|8=FIX.4.29=23235=D34=269649=Qa-QTIP-Sim-A56=Qa-QTIP-Sim-A-Internal52=20070604-23:31:2540=1MDSNAPID=6071=511=Q8BO7023-121=4955=QQQQ59=05011=12463/2007-06-04-07:3138=100109=RajTest5012=Raj9040=NSTRATEGY=PassThru54=147=A100=ARCA10=169|0|\r"; String fixString = newLine; string[] fixArray = fixString.Split(Convert.ToChar(1)); //I used 1 because FIX message uses this as delimiter... Hashtable fixTable = new Hashtable(); string[] fieldArray = null; try { for (int fieldCount = 0; fieldCount < fixArray.Length; fieldCount++) { fieldArray = fixArray[fieldCount].Split('='); fixTable.Add(fieldArray[0].ToString(), fieldArray[1].ToString()); } } catch { } string firstTagString = fixTable["100"].ToString(); MessageBox.Show(firstTagString); } catch (Exception ex) { MessageBox.Show(ex.Message); } Let me know if this works...

                  A 1 Reply Last reply
                  0
                  • M Manas Bhardwaj

                    Here it is: try { string newLine = "M|2696|0|D|I|20070604-19:31:25.177|255|8=FIX.4.29=23235=D34=269649=Qa-QTIP-Sim-A56=Qa-QTIP-Sim-A-Internal52=20070604-23:31:2540=1MDSNAPID=6071=511=Q8BO7023-121=4955=QQQQ59=05011=12463/2007-06-04-07:3138=100109=RajTest5012=Raj9040=NSTRATEGY=PassThru54=147=A100=ARCA10=169|0|\r"; String fixString = newLine; string[] fixArray = fixString.Split(Convert.ToChar(1)); //I used 1 because FIX message uses this as delimiter... Hashtable fixTable = new Hashtable(); string[] fieldArray = null; try { for (int fieldCount = 0; fieldCount < fixArray.Length; fieldCount++) { fieldArray = fixArray[fieldCount].Split('='); fixTable.Add(fieldArray[0].ToString(), fieldArray[1].ToString()); } } catch { } string firstTagString = fixTable["100"].ToString(); MessageBox.Show(firstTagString); } catch (Exception ex) { MessageBox.Show(ex.Message); } Let me know if this works...

                    A Offline
                    A Offline
                    Ankit Aneja
                    wrote on last edited by
                    #12

                    after this line string firstTagString = fixTable["100"].ToString(); it jumps out and go to lines after catch (Exception ex) { MessageBox.Show(ex.Message); }

                    Ankit Aneja "Nothing is impossible. The word itself says - I M possible"

                    M 1 Reply Last reply
                    0
                    • A Ankit Aneja

                      after this line string firstTagString = fixTable["100"].ToString(); it jumps out and go to lines after catch (Exception ex) { MessageBox.Show(ex.Message); }

                      Ankit Aneja "Nothing is impossible. The word itself says - I M possible"

                      M Offline
                      M Offline
                      Manas Bhardwaj
                      wrote on last edited by
                      #13

                      Dude, I ran it with the same code... If it is running for exception than it means ur message did not contain message with tag 100... nyway, for which company do you work?

                      A 1 Reply Last reply
                      0
                      • M Manas Bhardwaj

                        Dude, I ran it with the same code... If it is running for exception than it means ur message did not contain message with tag 100... nyway, for which company do you work?

                        A Offline
                        A Offline
                        Ankit Aneja
                        wrote on last edited by
                        #14

                        ya it works fine catched the exception then read the value thanks a lot for help

                        Ankit Aneja "Nothing is impossible. The word itself says - I M possible"

                        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