Jump to content

open txt and get string between lines ??


Recommended Posts

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 by hani-dev
Link to comment
Share on other sites

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

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

Link to comment
Share on other sites

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 :D it's working for me very well thanx dany

Link to comment
Share on other sites

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])

 

Link to comment
Share on other sites

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

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

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...