TiRep 0 Posted June 7, 2019 Hi. How would you parse the string bellow? Which format is it? Thank you for help. a:13:{i:0;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:1;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:2;a:5:{s:7:"section";s:1:"1";s:6:"levels";a:7:{i:0;s:1:"1";i:1;s:1:"1";i:2;s:1:"1";i:3;s:1:"1";i:4;s:1:"1";i:5;s:1:"1";i:6;s:1:"1";}s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:3;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:4;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:5;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:6;a:5:{s:7:"section";s:1:"1";s:6:"levels";a:1:{i:2;s:1:"1";}s:4:"date";s:10:"05.06.2019";s:4:"time";s:5:"12:35";s:3:"end";s:0:"";}i:7;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"05.06.2019";s:4:"time";s:5:"12:25";s:3:"end";s:10:"08.06.2019";}i:8;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:9;a:5:{s:7:"section";s:1:"1";s:6:"levels";a:10:{i:0;s:1:"1";i:1;s:1:"1";i:2;s:1:"1";i:3;s:1:"1";i:4;s:1:"1";i:5;s:1:"1";i:6;s:1:"1";i:7;s:1:"1";i:8;s:1:"1";i:9;s:1:"1";}s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:10;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:11;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:13;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"05.06.2019";s:4:"time";s:5:"13:34";s:3:"end";s:0:"";}} Share this post Link to post Share on other sites
JLogan3o13 1,637 Posted June 7, 2019 (edited) @TiRep welcome to the forum. You unfortunately could not have provided less information if you'd been actively trying. How about telling us where the string originates from (application, website, etc.), what it represents, how you are trying to parse it, etc. etc. Help us help you. Also, please see the link in my signature about how to ask smart questions on the forum. Edited June 7, 2019 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Share this post Link to post Share on other sites
iamtheky 927 Posted June 7, 2019 it is parsed, and it looks like JSON but JSON looks like a lot of other stuff. ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Share this post Link to post Share on other sites
Quual 1 Posted June 8, 2019 expandcollapse popupLocal $sData = 'a:13:{i:0;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:1;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:2;a:5:{s:7:"section";s:1:"1";s:6:"levels";a:7:{i:0;s:1:"1";i:1;s:1:"1";i:2;s:1:"1";i:3;s:1:"1";i:4;s:1:"1";i:5;s:1:"1";i:6;s:1:"1";}s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:3;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:4;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:5;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:6;a:5:{s:7:"section";s:1:"1";s:6:"levels";a:1:{i:2;s:1:"1";}s:4:"date";s:10:"05.06.2019";s:4:"time";s:5:"12:35";s:3:"end";s:0:"";}i:7;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"05.06.2019";s:4:"time";s:5:"12:25";s:3:"end";s:10:"08.06.2019";}i:8;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:9;a:5:{s:7:"section";s:1:"1";s:6:"levels";a:10:{i:0;s:1:"1";i:1;s:1:"1";i:2;s:1:"1";i:3;s:1:"1";i:4;s:1:"1";i:5;s:1:"1";i:6;s:1:"1";i:7;s:1:"1";i:8;s:1:"1";i:9;s:1:"1";}s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:10;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:11;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:13;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"05.06.2019";s:4:"time";s:5:"13:34";s:3:"end";s:0:"";' Parse($sData) Func Parse($sData) Local $rx = StringRegExp($sData,'(a:\d+:\{)|(s:\d+:"[^"]*";)(a:\d+:\{)|(s:\d+:"[^"]*";s:\d+:"[^"]*";)|(i:\d+;)|(\})',3), $vsOut[1][2] = [[0]], $iTabs = 0, $sTabs For $d In $rx If $d Then $sTabs = _repeat(@TAB, $iTabs) Select Case StringRegExp($d, 's:\d+:"([^"]+)";s:\d+:"([^"]*)";', 0) $r = StringRegExp($d, 's:\d+:"([^"]+)";s:\d+:"([^"]*)";', 3) _addToArray($vsOut, $sTabs, $r[0] & " = ", $r[1]) Case StringRegExp($d, 's:\d+:"([^"]+)";', 0) _addToArray($vsOut, $sTabs, StringRegExpReplace($d, '(s:\d+:")([^"]+)(");', '$2'), '') Case StringRegExp($d, 'i:\d+;', 0) _addToArray($vsOut, $sTabs, 'Element' & " # ", StringRegExpReplace($d, '(i:)(\d+)(;)', '$2')) Case StringRegExp($d, 'a:\d+:\{', 0) _addToArray($vsOut, $sTabs, 'Array[', StringRegExpReplace($d, '(a:)(\d+)(:\{)', '$2') & '] = {') $iTabs += 1 Case $d = '}' _addToArray($vsOut, $sTabs, '}', '') $iTabs -= 1 Case Else If $d Then ConsoleWrite('The following data was unhandeled [' & $d & ']' & @CRLF) EndSelect EndIf Next For $i = 1 To $vsOut[0][0] ConsoleWrite($vsOut[$i][0] & $vsOut[$i][1] & @CRLF) Next EndFunc Func _addToArray(ByRef $a, $sTabs, $ele0, $ele1) $a[0][0] += 1 ReDim $a[$a[0][0] + 1][2] $a[$a[0][0]][0] = $sTabs & $ele0 $a[$a[0][0]][1] = $ele1 EndFunc Func _repeat($sStr, $i) Local $sRet = '' For $n = 1 To $i $sRet &= $sStr Next Return $sRet EndFunc I was bored so i wrote a little script to parse the data, it does a fair job of it. Share this post Link to post Share on other sites