Jump to content

Splitting on spaces using StringSplit


c0re
 Share

Recommended Posts

Hi everyone,

2 things -

Question #1

Is there a way to redirect output from a program to an array instead of a file then reading the file into an array?

If I use a line like this:

Dim $array
$array = RunWait(@ComSpec & " /c " & 'c:\temp\check\psexec.exe \\' & $psiservers[$x] & ' -s -c process.exe -c |findstr -i powersi', 'c:\temp\check', @SW_HIDE)oÝ÷ Øw«z+ìZ^¡ûazËkxßÙ­¯(§Ú,¦X­¶¬¥§²­¡øì^ï^´ßÍ5óý=ÿm4ëm6×mÁ« ¢)à¶h¢a® Mú²b¶·¦¢ø§©e¶rzW¦z{+a²¶§X¤y«­¢+Ù½ÈÀÌØíÈôÄѼÀÌØíÍÁ±¥ÑlÁt(%ÀÌØíÍÁ±¥ÑlÀÌØíÉtôÅÕ½ÐìÅÕ½ÐìQ¡¸(}ÉÉå±Ñ ÀÌØíÍÁ±¥Ð°ÀÌØíȤ(¹%)9áÐ

This bombed with some "Array variable has incorrect number of subscripts or subscript dimension range exceeded" errors so then I tried using UBound($split)-1 instead of $split[0] but got the same errors.

I figured I must be doing something wrong as I'm sure many of you do this all the time; so here I am :).

Any help offered is appreciated.

Thanks.

Link to comment
Share on other sites

1. look at StdoutRead

2. you already have

$split = StringSplit("7160 3 8 0 18/09/2006 20:21:20"," ")
For $x = 1 To $split[0]
    MsgBox(0,$x,$split[$x])
Next
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

1. Thanks for the StdoutRead tip, I'm checking into that.

2. When I pasted in the line I was splitting to the forum post earlier it cut out all the reoccurring spaces for some reason. So, while StringSplit may remove some of the spaces it does not remove them all. I still end up with many spaces in $split. Here is an example of what the array looks like after I do the StringSplit:

[0]=30

[1]=

[2]=

[3]=

[4]=

[5]=

[6]=

[7]= gen.exe

[8]=

[9]= 7160

[10]=

...empty elements to 16

[16] = 3

...empty elements to 24

[24] = 8

[25] =

[26] =

[27] = 0

[28] =

[29] = 18/09/2006

[30] = 20:21:20

The problem is these empty elements change on me from iteration to iteration, [30] may not contain the time but instead will contain an empty element or no element at all. :)

Link to comment
Share on other sites

  • Developers

try:

$split = StringSplit(StringStripWS("7160       3           8 0 18/09/2006 20:21:20",4)," ")
For $x = 1 To $split[0]
    MsgBox(0,$x,$split[$x])
Next

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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