Jump to content

Read a variable and extract 3 caracters


Kyan
 Share

Recommended Posts

Hi,

Can someone tell me whats the combination of commands to read a variable (downloaded from internet), search for a specific string like "FileSize=" and extract the next 3 caracters in front this string?

I already write this:

$dtxt = BinaryToString ($readtxt)
   $txtsplit = StringSplit($dtxt,"FileSize=",1)
   $ver = StringTrimLeft($txtsplit[1],3)

but gives-me nothing or 25 :s

Thanks for your time :)

EDIT: the start is "FileSize=" the end of this parameter is a semicolon

Edited by DiOgO

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Link to comment
Share on other sites

I'm digging arround but I cannot get the first 2 digits, and the next 2 forward the dot: StringRegExp($txtsplit[2], '([0-9]{1,2})[.]([0-9]{1,2})', 1)

example: FileSize=34.94MB

please help me out :)

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Link to comment
Share on other sites

$dtxt = BinaryToString ($readtxt)
   $txtsplit = StringSplit($dtxt,"FileSize=",1)
   $ver = StringTrimLeft($txtsplit[1],3)

What are you trying to do with the BinaryToString Function? if you are trying to read a variable to string, theres no need for that because you could read the string strait away without the need of converting.

Can someone tell me whats the combination of commands to read a variable (downloaded from internet)

What do you mean; do you want to download a file from the internet?

I'm digging arround but I cannot get the first 2 digits, and the next 2 forward the dot: StringRegExp($txtsplit[2], '([0-9]{1,2})[.]([0-9]{1,2})', 1)

example: FileSize=34.94MB

please help me out :)

Do you want it like this:

$Size = StringRegExp("FileSize=34.94MB", '(?i)FileSize=(.*?)(.)MB', 1)
MsgBox(0,"",$Size[0])
Edited by Guest
Link to comment
Share on other sites

What are you trying to do with the BinaryToString Function? if you are trying to read a variable to string, theres no need for that because you could read the string strait away without the need of converting.

What do you mean; do you want to download a file from the internet?

Do you want it like this:

$Size = StringRegExp("FileSize=34.94MB", '(?i)FileSize=(.*?)(.)MB', 1)
MsgBox(0,"",$Size[0])

I'm trying to get the size of a file listed in a txt (previously downloaded from internet...) in this example is "34.94" MB

thanks btw

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Link to comment
Share on other sites

Here's a way using the _StringBetween() UDF.

#include <String.au3>
$string = "FileSize=34.94MB"
$array = _StringBetween($string, "FileSize=", "")
ConsoleWrite($array[0] & @LF)

awesome! thanks a lot :)

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Link to comment
Share on other sites

You bet. Good luck with the rest of your project. You should remember though, that $array[0] will contain everything after FileSize=.

and it don't work only with $array?

can I for example get 5 caracters before the searched string?

charsIwant--FileSize=...

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Link to comment
Share on other sites

Do you get this? Ask if you need clarification.

#include <String.au3>

$var1   = "FileName=foo.txt FileSize=34.94MB more text"
$var2   = " FileSize="

$array1 = _StringBetween($var1, $var2, "")
$array2 = StringSplit($var1, $var2, 1)

ConsoleWrite($array1[0] & @LF & StringRight($array2[1], 7) & @LF)

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to comment
Share on other sites

and it don't work only with $array?

can I for example get 5 caracters before the searched string?

charsIwant--FileSize=...

You can't use an Array as $array, it has to have a number at the end with brackets depending on the the number of things that are declared in the Array.

For example if my Array was something like below then if i wanted a value from a specific location such from row 1 column 1, it would be: $array[0][0]

$array[2][4] < this means that my array has 2 rows and 4 columns.

$array[2] < this means that my array has 2 rows and to get the value from this you use: $array[0] which will return the row 1 data.

This will return the two things you want:

$Size = StringRegExp("FileName=Dotx.txt FileSize=34.94MB", '(?i)(?s)FileName=(.*?).FileSize=(.*?).MB', 1)
MsgBox(0,"",$Size[0]); First value
MsgBox(0,"",$Size[1]); Seconde value
Link to comment
Share on other sites

1) This is not really the correct forum for this question.

2) DiOgO, I realize you are new at this, or maybe programming/scripting altogether, but these are the kind of threads and questions I hate. You are asking basic language questions, implying you haven't even opened the help file or done any reading on basic concepts such as strings, substrings, or arrays. You need to stop now, cease creating new threads, and do some work on your own. Once you have the basics down you can start to build things. THEN start in on regular expressions. They are confusing and an advanced concept... work up to it.

Once you've laid the ground work for what you want to do, you can come back and ask intelligent questions which may garner help from the more experienced people on this board. Most won't even take the time to write what I have so far until you've done at least that much.

Edited by wraithdu
Link to comment
Share on other sites

Do you get this? Ask if you need clarification.

#include <String.au3>

$var1   = "FileName=foo.txt FileSize=34.94MB more text"
$var2   = " FileSize="

$array1 = _StringBetween($var1, $var2, "")
$array2 = StringSplit($var1, $var2, 1)

ConsoleWrite($array1[0] & @LF & StringRight($array2[1], 7) & @LF)

yap, thanks :)

You can't use an Array as $array, it has to have a number at the end with brackets depending on the the number of things that are declared in the Array.

For example if my Array was something like below then if i wanted a value from a specific location such from row 1 column 1, it would be: $array[0][0]

$array[2][4] < this means that my array has 2 rows and 4 columns.

$array[2] < this means that my array has 2 rows and to get the value from this you use: $array[0] which will return the row 1 data.

This will return the two things you want:

$Size = StringRegExp("FileName=Dotx.txt FileSize=34.94MB", '(?i)(?s)FileName=(.*?).FileSize=(.*?).MB', 1)
MsgBox(0,"",$Size[0]); First value
MsgBox(0,"",$Size[1]); Seconde value

got it

1) This is not really the correct forum for this question.

2) DiOgO, I realize you are new at this, or maybe programming/scripting altogether, but these are the kind of threads and questions I hate. You are asking basic language questions, implying you haven't even opened the help file or done any reading on basic concepts such as strings, substrings, or arrays. You need to stop now, cease creating new threads, and do some work on your own. Once you have the basics down you can start to build things. THEN start in on regular expressions. They are confusing and an advanced concept... work up to it.

Once you've laid the ground work for what you want to do, you can come back and ask intelligent questions which may garner help from the more experienced people on this board. Most won't even take the time to write what I have so far until you've done at least that much.

sorry for that incovenint, I lost 3hours to get that string, I started a 2-3days ago scripting I already have done a program that checks a online file, gets a url from that txt plus other text, display it in the GUI, download the file with progress bar...etc...etc, and does the md5 hash check.

not bad for the first script, but there's somethings I don't know, I really spend many hours in the help file, but when I notice that I can't do it is when I asked. An example of this is the StringRegExp, I don't get it how combine all the parameters etc..

Once again sorry for the dumb questions and for the grammar inssues, my native language is not the english.

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Link to comment
Share on other sites

I'm not talking about inconvenience or language differences, but basic usage of things like arrays. That is all covered in the help file. FWIW, pretty lofty goal for a first script... so do it right!

For regex's, you should *start* here: http://www.autoitscript.com/autoit3/pcrepattern.html

That link is in the help file page you specified, BTW. Start there, but it is certainly not exhaustive on regex's. Google will find you more info that you could possibly need.

Edited by wraithdu
Link to comment
Share on other sites

I'm not talking about inconvenience or language differences, but basic usage of things like arrays. That is all covered in the help file. FWIW, pretty lofty goal for a first script... so do it right!

For regex's, you should *start* here: http://www.autoitscript.com/autoit3/pcrepattern.html

That link is in the help file page you specified, BTW. Start there, but it is certainly not exhaustive on regex's. Google will find you more info that you could possibly need.

thank you

its more easier with the command and the output related ;)

could you give a look at this topic: ?

just how to get the output percentage to a variable :)

and this is the way to check a combobox? seems much lines to verify all the checkbox...

Case $CompMenuItem0
   $readmenu = ""
   $readmenu = GUICtrlRead($CompMenuItem0)
   if $readmenu = 68 Then
      GUICtrlSetState($CompMenuItem0, $GUI_CHECKED)
      GUICtrlSetState($CompMenuItem1, $GUI_UNCHECKED)
      GUICtrlSetState($CompMenuItem2, $GUI_UNCHECKED)
      GUICtrlSetState($CompMenuItem3, $GUI_UNCHECKED)
      GUICtrlSetState($CompMenuItem4, $GUI_UNCHECKED)
      GUICtrlSetState($CompMenuItem5, $GUI_UNCHECKED)
   EndIf

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.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...