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. Conversion to xml

Conversion to xml

Scheduled Pinned Locked Moved C#
xmlquestion
3 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.
  • B Offline
    B Offline
    bidisha_tina
    wrote on last edited by
    #1

    I want to convert a string str="ABC=100 BC C=50" to xml as 100 = Is it possible? bidisha

    E L 2 Replies Last reply
    0
    • B bidisha_tina

      I want to convert a string str="ABC=100 BC C=50" to xml as 100 = Is it possible? bidisha

      E Offline
      E Offline
      exhaulted
      wrote on last edited by
      #2

      if everything is going to be space delimited then it's definately possible.

      string s = "abc=100 bc c=50 def=20"
      string[] strings = s.Split(" ");

      This will give you an array of xml elements split at each space " ". Then you've just gotta go through each one and work out whether or not it has an operator and create your xml file. Just make sure that the only spaces in the string are between elements, if you need spaces elsewhere then use a different character like a comma.

      string s = "abc=100,bc,c=50,def=20"
      string[] strings = s.Split(",");

      Cheers Kev

      1 Reply Last reply
      0
      • B bidisha_tina

        I want to convert a string str="ABC=100 BC C=50" to xml as 100 = Is it possible? bidisha

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        MatchCollection matches = Regex.Matches(str, @"(?<name>[^=\s]+)(=(?<value>\d+))?"); Use this regular expression. This will give you a match collection with the captures "name" and "value". It's easy to transform this into an XML then. regards

        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