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

Discuss and share scripts and script files...
Post Reply
Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

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

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

admin
Site Admin
Posts: 66075
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

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

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

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

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

Post 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 ;-)

admin
Site Admin
Posts: 66075
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

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

Post 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. :)

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

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

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

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

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

Post by Stefan »

Thank you TheQwerty

Post Reply