Jump to content

Need a help in String Split and storing it in array


Recommended Posts

Hi Everyone,

i am a complete beginner to autoit and i am in a learning stage,so if this question looks so dumb,pls pardon me.

Can anyone help me with a code where i want to take only particular values from a text and store it to array

I have shared the input text which i have in below code window and i want to take only text's inside the Value tag ex:  "Value":"Copy_anything_inside_this"

i.e: "Value":"Jan 2016" ---->Copy Jan 2016 into a array[0,0]

"Value":"5.99"  --->Copy 5.99 into a array[0,1]

etc

 

{  
   "records":[  
      {  
         "checkbox":{  
            "marked":false,
            "rowNum":"0",
            "sortable":false
         },
         "0":{  
            "value":"Dec 2015"
         },
         "1":{  
            "id":"0_0",
            "value":"6.38"
         }
      },
      {  
         "checkbox":{  
            "marked":false,
            "rowNum":"1",
            "sortable":false
         },
         "0":{  
            "value":"Jan 2016"
         },
         "1":{  
            "id":"0_1",
            "value":"5.99"
         }
      },
      {  
         "checkbox":{  
            "marked":false,
            "rowNum":"2",
            "sortable":false
         },
         "0":{  
            "value":"Feb 2016"
         },
         "1":{  
            "id":"0_2",
            "value":"5.73"
         }
      },
      {  
         "checkbox":{  
            "marked":false,
            "rowNum":"3",
            "sortable":false
         },
         "0":{  
            "value":"Mar 2016"
         },
         "1":{  
            "id":"0_3",
            "value":"6.51"
         }
      }
   ],
   "recordsReturned":12,
   "totalRecords":12,
   "pageSize":25,
   "startIndex":0,
   "sort":"Timestamp",
   "dir":"ASC",
   "pclassid":0,
   "metadata":[  

   ]
}

 

Can anyone give me a rough idea how can i do this?

Link to comment
Share on other sites

this is pretty rough

#include<array.au3>
_ArrayDisplay(StringRegExp(fileread("jsonstring.txt") , '".+"\:"(.+)"' , 3))

 

 

edit:  if you want the labels just capture that whole group (remove the parentheses) and then split each line on the colon?

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

May I suggest

#include <Array.au3>

$array = StringRegExp(Fileread("jsonstring.txt") , 'value":"([^"]*)' , 3)
Local $res[UBound($array)/2][2]
For $i = 0 to UBound($array)-1 step 2
     For $j = 0 to 1
          $res[$i/2][$j] = $array[$i+$j]
     Next
Next
_ArrayDisplay($res)

 

Edit :  :)

Edited by mikell
Link to comment
Share on other sites

@mikell he said "rough" answers. :)

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

10 hours ago, mikell said:

May I suggest

#include <Array.au3>

$array = StringRegExp(Fileread("jsonstring.txt") , 'value":"([^"]*)' , 3)
Local $res[UBound($array)/2][2]
For $i = 0 to UBound($array)-1 step 2
     For $j = 0 to 1
          $res[$i/2][$j] = $array[$i+$j]
     Next
Next
_ArrayDisplay($res)

 

Edit :  :)

Tht's it :) It worked as I wanted:). Thanks a lot @iamtheky @mikell .

JSON to array.PNG

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...