Jump to content

I Think It's Called "Concatenating"...


Jon8c
 Share

Recommended Posts

Well, to be straightforward, I do think this is a stupid question, but I can't seem to make it work... First of all, here is a part of my script:

#Include <Array.au3>
#Include <File.au3>
$Files=_FileListToArray("C:\Documents and Settings\***\Desktop\New Folder","*",1)
$File=_ArrayToString($Files,"",1,1)
$Match=StringRegExp($File,'[[:alpha:]\A]*',1)
$List1=_ArrayToString($Files,",")
$List2=StringRegExp($List1,$Match&'[^,]*',3)

After testing a bit, the only problem I have left is the fact that I can't seem to make the string stored as $Match to combine with "[^,]*" in order for my desired pattern to work. To put it more plainly, for instance, $Match would result to be the string "abduction" and so, I would want "'abduction[^,]*'" where "$Match&'[^,]*'" currently is. When I simply use "'abduction[^,]*'" as a pattern, the script works fine, but the thing is that "abduction" will not always be the $Match string and I don't intend it to be. I referred to the Help file of course, and recalled that the operator "&" and "&=" involve combining/"concatenating" (according to the Help file) two strings/values. But, I'm figuring that somehow AutoIt doesn't consider "[^,]*" a string? I also tried setting that as a different variable and combining it that way, but it didn't work. Maybe I'm using it wrong or something. Been awhile since I touched AutoIt to be honest. Yet, I remember it worked well the last time I tried using the operator. Well, I'll stop jabbering now. Thanks in advance.

Link to comment
Share on other sites

I'll be sure to try that, but I kinda doubt it'll work tbh. Yeah, StringRegExp is supposed to return an array of matches, but I figured out that the flag "1" makes the function only report the first match or something, because I was using the same function elsewhere and it wouldn't report all matches unless I set it to flag "3" to return global matches.

EDIT: Wth... it worked lol. Thanks for the tip. I'll be sure to keep that in mind from now on.

EDIT2: While I'm at it, btw, do only built-in functions automatically set a variable as an array if it returns multiple data? I mean, I remember I tried using a user-defined function provided through the AutoIt package and the function returned the proper strings/data, but AutoIt would not let me use $Var[0] or any other index. I could only use $Var as a whole.

Edited by Jon8c
Link to comment
Share on other sites

If you have a look at the help file, you will see the return value for specific functions. Some will return 1 or a handle on sucess, others will return an array etc. It depends on the function. :)

Cheers,

Brett

Link to comment
Share on other sites

Well, I remember I was messing around with the user-defined function "_FileListToArray" and set it to return data to a variable $Var, lets say. The Help file clearly said this:

The array returned is one-dimensional and is made up as follows:

$array[0] = Number of Files\Folders returned

$array[1] = 1st File\Folder

$array[2] = 2nd File\Folder

$array[3] = 3rd File\Folder

$array[n] = nth File\Folder

Yet, whenever I tried to use "$Var[0]", AutoIt would send me an error saying $Var isn't an array variable. But, if I use StringRegExp to return data to $Var, $Var is automatically set or recognized as an array. It's not really a problem now since I bypassed my dilemma, but is there a reason for this? Or, am I just missing something o.o?
Link to comment
Share on other sites

Well, maybe, but I don't think so (I probably am wrong, already was early today =.=). I tried several set-ups using "_FileListToArray", each still giving me the error. So, I finally decided to bypass the use of "$Var[0]" by converting the array into a string using "_ArrayToString". Luckily for me, in my case, it didn't matter whether or not my list of files was an array or string. In fact, I think it works better as a string, now that I think of it. But, that failed reference to an array index still puzzles me though. This wasn't the only time it happened. I remember way back when I made scripts for games (yesh, I cheat, leaves me alones >.<), I faced the same annoying problem. Am I supposed to declare them first or something? I think I tried that before but again to no avail. Sigh, I'm certainly confuzzled now.

Link to comment
Share on other sites

Heh, well, tbh, I don't really have the problem anymore, like I said. I worked around it. What I posted in my first post of this topic is what I have left (after cleaning up a few things). I was just wondering if this was common or something, because it always happened to me. Since my main question has already been answered (thanks, again), I'm not really going to focus on this annoying phenomenon. Just wanted to see if anyone had a simple answer, like you guys always do >.> lol.

Link to comment
Share on other sites

  • Moderators

The way to declare a variable as an array is:

Dim/Local/Global $a_array[Number of Elements in your array + 1]
(That is pseudo code, it won't work in real life).

So just saying I want $a_array[0] to = 19 doesn't work, unless I declared $a_array an array with Dim/Global/Local and with the brackets surrounded by the total number of elements I'm using + 1.

Other functions such as StringRegExp() or StringSplit() will make $a_array an array "auto-magically", by using something like Local $a_array = StringSplit("a,b,c", ","), now $a_array is an array, but to declare one on your own, you must first make it one.

This might help:

http://www.autoitscript.com/wiki/Arrays

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Oh, so some functions just make the array for you and some don't? I can see that. But, there's still one thing I don't understand. For "_FileListToArray", the variable with its return data "works" like an array since I can use "_ArrayToString" to convert it to a string or use "_ArrayDisplay" to bring up a small window displaying its data, but I can't go ahead and use $Var[0]? (P.S. Thanks for the link, cleared up some other thoughts...)

EDIT: Nevermind. I think I'm an idiot rofl. I think I misspelled something... And, I examined file.au3 and "_FileListToArray" does call an array properly. So, end of discussion, I guess =.=". Thanks for all the help...again. I'll be back sometime later. Bwhahahaha.

Edited by Jon8c
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...