Page 1 of 1

Question: For...Next and Split($a,"\")

Posted: 26 Nov 2008 00:09
by Stefan
I have searched but didn't find an hint...

Question 1)
I have var $a and want to split them by char or line break:

My $a contains f.ex.:
File1.txt
File2,txt
File3.txt
$array = Split($a,"\n")
msg $array(1)
new $array(1)


or
$b = X:\one\two\three\file4.txt
$array = Split($b,"\")
msg $array(0) . "..." . UBound($array)


How can i split such contents into parts?



Question 2)
How can i do an For..Next Statement ?

For Each Part in $a
doit
Next



or

For i = 1 TO UBound($array)
doit
i++
Next


-------
And an other thing i want to know

readfile(filename, [mode])

How can i do

$line = readfile(filename, LineNo(1))

or
For x = 1 TO EOF
$lineArray = readfile(filename, LineNo(x))
new file $lineArray(x)
x++
Next

?
THX for an answer ;-)


----
Edit:

f.ex. i want to script

Code: Select all

input $output, caption, , m;
msg $output;
$array = Split($output, NL);
  For i = 1 To UpperBound($array)
    new $array(i) ;
    i = i + 1
  Next
msg $output
abereine.txt
aberzwei.txt
aber drei.txt


to create a few files there names i have copied from text file or an web side for testing issues.
(currently i use batch or ahk script, but want to do this with XY scripting if possible)

Re: Question: For...Next and Split($a,"\")

Posted: 26 Nov 2008 09:19
by admin

Code: Select all

input $output, caption, , m;
msg $output;
$array = Split($output, NL);
  For i = 1 To UpperBound($array)
    new $array(i) ;
    i = i + 1
  Next
Yes, I'd like to do this, too. It's not possible right now (unless maybe with the wildest workarounds). However, it's on my list and some day it will come.... (same with your other wishes).

Re: Question: For...Next and Split($a,"\")

Posted: 26 Nov 2008 10:10
by Stefan
Ahh, thank you, :D so it was not me not finding it.

BTW, isn't it possible to integrate something like WSH scripting features...like PSPad does ? .. so users could use VBS or JS for scripting to.

Or maybe something like the AutoIt-ActiveX DLL with COM support ?

Sorry, didn't know if this would be possible or how many work this needs..... just brain storming ;-)

Re: Question: For...Next and Split($a,"\")

Posted: 26 Nov 2008 10:28
by admin
Stefan wrote:Ahh, thank you, :D so it was not me not finding it.

BTW, isn't it possible to integrate something like WSH scripting features...like PSPad does ? .. so users could use VBS or JS for scripting to.

Or maybe something like the AutoIt-ActiveX DLL with COM support ?

Sorry, didn't know if this would be possible or how many work this needs..... just brain storming ;-)
No, I like to keep it pure. :)

Re: Question: For...Next and Split($a,"\")

Posted: 26 Nov 2008 13:24
by TheQwerty
Well, you can accomplish the splitting by using GetToken().

By character requires that you first insert a delimiter into the string:

Code: Select all

RegExReplace($v, "asdf", "(.)","$1|"); //$v is 'a|s|d|f|'
$v = GetToken($v,"2","|"); //$v should be 's'
Or you could just do it using SubStr():

Code: Select all

SubStr($v, "asdf", "1", "1");
You can also use GetToken() with a delimiter of "<crlf>" to split on lines.

To do something to each token or get a count of tokens currently requires some recursive work, but it's possible.

Re: Question: For...Next and Split($a,"\")

Posted: 26 Jun 2009 20:31
by Stefan
Thank you TheQwerty