hani-dev Posted July 11, 2016 Share Posted July 11, 2016 (edited) hello there ... im trying to get this number from txt file Quote {"ORIGINAL_USER_ID":"732551212"} this string inside my .txt source code how can i get this value in msgbox : 732551212 note : this value is changed always thanx all Edited July 11, 2016 by hani-dev Link to comment Share on other sites More sharing options...
Valuater Posted July 11, 2016 Share Posted July 11, 2016 This is one way... $Lstring = '{"ORIGINAL_USER_ID":"732551212"}' $Sstring = StringSplit($Lstring, '"') MsgBox(0, "String", $Sstring[4]) 8) Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted July 11, 2016 Share Posted July 11, 2016 That should be really easy. Go look at the functions FileRead() and _StringBetween() If you cant get it working post your code and we can help you on the next steps. Link to comment Share on other sites More sharing options...
hani-dev Posted July 11, 2016 Author Share Posted July 11, 2016 20 minutes ago, Valuater said: This is one way... $Lstring = '{"ORIGINAL_USER_ID":"732551212"}' $Sstring = StringSplit($Lstring, '"') MsgBox(0, "String", $Sstring[4]) 8) it's working man thanx very much but can u expalin why we use [4] i dont want just to copy and paste i need to understand Link to comment Share on other sites More sharing options...
Danyfirex Posted July 11, 2016 Share Posted July 11, 2016 You can do something like this: #include <StringConstants.au3> Local $sData = FileRead("1.txt") ConsoleWrite($sData & @CRLF) Local $aResult = StringRegExp($sData, '(?:"ORIGINAL_USER_ID"):([^\{,}]+)', $STR_REGEXPARRAYGLOBALMATCH) $sORIGINAL_USER_ID=StringReplace($aResult[0],'"','') MsgBox(0,"",$sORIGINAL_USER_ID) Saludos hani-dev 1 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
hani-dev Posted July 11, 2016 Author Share Posted July 11, 2016 2 minutes ago, Danyfirex said: You can do something like this: #include <StringConstants.au3> Local $sData = FileRead("1.txt") ConsoleWrite($sData & @CRLF) Local $aResult = StringRegExp($sData, '(?:"ORIGINAL_USER_ID"):([^\{,}]+)', $STR_REGEXPARRAYGLOBALMATCH) $sORIGINAL_USER_ID=StringReplace($aResult[0],'"','') MsgBox(0,"",$sORIGINAL_USER_ID) Saludos u are the best it's working for me very well thanx dany Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted July 11, 2016 Share Posted July 11, 2016 lol, since this was a good first timer script I figured I would see if he could figure it out. But with all the complicated solutions posted, I may as well share what I feel is the most basic one. #Include <String.au3> $sString = FileRead(@ScriptDir & "\YourFile.txt") $aResult = _StringBetween($sString, 'ORIGINAL_USER_ID":"', '"}') MsgBox(0, "", $aResult[0]) AutoBert 1 Link to comment Share on other sites More sharing options...
kylomas Posted July 11, 2016 Share Posted July 11, 2016 Quote how can i get this value in msgbox : 732551212 $Lstring = '{"ORIGINAL_USER_ID":"732551212"}' MsgBox(0, "String", stringregexpreplace($Lstring,'.*:"(\d+)"}','$1')) ...Just for grins... Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
mikell Posted July 11, 2016 Share Posted July 11, 2016 kylomas, Grins indeed because this "txt" file looks a lot like a json This deserves a one-liner - just for the fun MsgBox(0,"", StringRegExpReplace(FileRead("1.txt"), '(?s).*ORIGINAL_USER_ID":"([^"]+).*', "$1") ) Link to comment Share on other sites More sharing options...
jvds Posted July 12, 2016 Share Posted July 12, 2016 8 hours ago, hani-dev said: it's working man thanx very much but can u expalin why we use [4] i dont want just to copy and paste i need to understand because stringsplit returns an array with the elements and your info is on the array element number 4, $Sstring is an array, not a string anymore in other words '{"ORIGINAL_USER_ID":"732551212"}' is your pizza, and when you slice it on every " character you have an array, and each slice(element) have a piece of pizza(string) in it, in this case your pizza have 5 slices if you cut it on the " character =P #include <StringConstants.au3> #include <Array.au3> $Lstring = '{"ORIGINAL_USER_ID":"732551212"}' $Sstring = StringSplit($Lstring, '"') ;~ MsgBox(0, "String", $Sstring[4]) _ArrayDisplay($Sstring) ConsoleWrite('$Sstring[3]='&$Sstring[3]&@CRLF) ConsoleWrite('$Sstring[4]='&$Sstring[4]&@CRLF) ConsoleWrite('$Sstring[5]='&$Sstring[5]&@CRLF) ;$Sstring[6] will crash your script because there is only 5 elements ;~ ConsoleWrite('$Sstring[6]='&$Sstring[4]&@CRLF) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now