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. Web Development
  3. JavaScript
  4. function for split a complex string

function for split a complex string

Scheduled Pinned Locked Moved JavaScript
questiontutorial
4 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
    mhd sbt
    wrote on last edited by
    #1

    hi to all i have a string with this format x=numbery=datez=number... for example of this string can be : x=123y=2013/02/01z=12345p=111 i want a function that get me this x=123 y=2013/02/01 z=12345 p=111 how can i do this? note to this point that my string can not be change and add extra character to this string thanks in advance

    Z D N 3 Replies Last reply
    0
    • M mhd sbt

      hi to all i have a string with this format x=numbery=datez=number... for example of this string can be : x=123y=2013/02/01z=12345p=111 i want a function that get me this x=123 y=2013/02/01 z=12345 p=111 how can i do this? note to this point that my string can not be change and add extra character to this string thanks in advance

      Z Offline
      Z Offline
      ZurdoDev
      wrote on last edited by
      #2

      There is usually many ways to do string manipulation but one way would be to split on the = and then you'll have the rightmost character to be the starting of your next string. You'll have to put in a case for the first one. Or, just loop through each character and process.

      There are only 10 types of people in the world, those who understand binary and those who don't.

      1 Reply Last reply
      0
      • M mhd sbt

        hi to all i have a string with this format x=numbery=datez=number... for example of this string can be : x=123y=2013/02/01z=12345p=111 i want a function that get me this x=123 y=2013/02/01 z=12345 p=111 how can i do this? note to this point that my string can not be change and add extra character to this string thanks in advance

        D Offline
        D Offline
        Dennis E White
        wrote on last edited by
        #3

        you have to define what are the valid characters that can be on the left hand side of the '=' sign. in other words can you have something like the following? pa1n=1234h1nd=4321gr33d=6789 pa1n=1234 h1nd=4321 gr33d=6789 that gets a lot more difficult vs if you only allow stuff on the left to be alpha characters and then stuff on the right to be numeric and special characters. sounds like a homework question from a programming class.

        as if the facebook, twitter and message boards weren't enough - blogged

        1 Reply Last reply
        0
        • M mhd sbt

          hi to all i have a string with this format x=numbery=datez=number... for example of this string can be : x=123y=2013/02/01z=12345p=111 i want a function that get me this x=123 y=2013/02/01 z=12345 p=111 how can i do this? note to this point that my string can not be change and add extra character to this string thanks in advance

          N Offline
          N Offline
          Niral Soni
          wrote on last edited by
          #4

          function splitString(myStr) {
          var regex = new RegExp(/[a-z]+[0-9]*[a-z]*=/ig);
          var keyPairs = myStr.match(regex).join('').split('=');
          var valuePairs = myStr.split(regex);
          document.write('======== Start ==========
          ');
          document.write('INPUT: ** ' + myStr + '**
          ');

          var map = {};
          for(var i = 0; i < keyPairs.length - 1; i++) {
              map\[keyPairs\[i\]\] = valuePairs\[i+1\];
          }
          for(key in map) {
              document.write(key + ' = ' + map\[key\] + '  
          

          ');
          }
          document.write('======== End ==========

          ');
          }

          splitString('x=123y=2013/02/01z=12345p=111');
          splitString('pa1n=1234h1nd=4321gr33d=6789');

          Thanks & Regards, Niral Soni

          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