Jump to content

split strings


Recommended Posts

Hello, i'm trying to make a GUI application for Wii using dos Exe "wbfs_win.exe".

When I list games on Harddisk, i stock this cmd return in a variable :

CODE
wbfs windows port build 'delta'

SXBP22 Wii fit PAL 1.75G

SXAP52 Guitar Hero: World Tour 3.95G

SXBE52 Guitar Hero Metallica 4.13G

I need to seperate IDs, names and spaceUsed in different array or variables ( ex : SXAP52, Guitar Hero: Word Tour, 3.95G )

How can i do ?

Edited by sambalec
Link to comment
Share on other sites

I'm trying but i have problem to split name of the game using stringbetween :

CODE
#include <String.au3>

$var = "SXAP52 Guitar Hero: World Tour 3.95G"

$id = StringLeft($var, 6)

Msgbox(0,"Game ID",$id)

$size = StringRight($var, 5)

Msgbox(0,"Game Size",$size)

$name = _StringBetween ($var, $id, $size)

Msgbox(0,"Game Name",$name)

_StringBetween problem i think...

Edited by sambalec
Link to comment
Share on other sites

I'm trying but i have problem to split name of the game using stringbetween :

CODE
#include <String.au3>

$var = "SXAP52 Guitar Hero: World Tour 3.95G"

$id = StringLeft($var, 6)

Msgbox(0,"Game ID",$id)

$size = StringRight($var, 5)

Msgbox(0,"Game Size",$size)

$name = _StringBetween ($var, $id, $size)

Msgbox(0,"Game Name",$name)

_StringBetween problem i think...
why don't you use one string split and return all the things?

StringSplit ($Var, " ") gives you
$Split[0] - the count
$Split[1] - the id
$GameName = $Split[2] 
For $i = 3 to $Split[0] - 1
$GameName &= " " & $Split[$i]
Next
$Split[$Split[0]] - the size
Link to comment
Share on other sites

I don't really understand your code... sry

its not much of a code sorry...i'm just showing the returns. The code could be more like this:

$Split = StringSplit ($Var, " ")
MsgBox (48, "The count is", $Split[0])
MsgBox (48, "The id is", $Split[1])
$GameName = $Split[2]
For $i = 3 to $Split[0] - 1
$GameName &= " " & $Split[$i]
Next
MsgBox (48, "The name is", $GameName)
MsgBox (48, "The size is", $Split[$Split[0]])
Link to comment
Share on other sites

?? not getting a stringsplit, but getting stringregexp....

what is autoit coming to?

all i'm doing is splitting up the statement at every space, and getting an array. the first $Split[1] is SXBE52, 2 is Guitar, 3 is Hero etc.

then I'm cancatenating all of them except the first and last to leave you with one string for Guitar Hero Metallica. This way you can index all of the things id, name and size, using one function.

RegExp is better, but mine should be easier to understand if i explain it properly.

Link to comment
Share on other sites

Hello, i'm trying to make a GUI application for Wii using dos Exe "wbfs_win.exe".

When I list games on Harddisk, i stock this cmd return in a variable :

CODE
wbfs windows port build 'delta'

SXBP22 Wii fit PAL 1.75G

SXAP52 Guitar Hero: World Tour 3.95G

SXBE52 Guitar Hero Metallica 4.13G

I need to seperate IDs, names and spaceUsed in different array or variables ( ex : SXAP52, Guitar Hero: Word Tour, 3.95G )

How can i do ?

I haven't tested this, but just hammered it out on the keyboard.

It may not work because of a typo or something, but the theory should be ok.

#include <String.au3>

;Here you use your cmd to get the output of data - contains ID, games, HDD space.
$output = .... 

;Next we want to split the output into lines. Note line 1 will be the "wbfs" info, line 2 would be blank. Game info starts on line 3
$lines = StringSplit($output, @CRLF, 0)

;Starting at line 3, loop through all lines until the last line (total lines defined at $lines[0]).
For $i = 3 to $lines[0] Step +1
  ;Split the text of each line where there is a space.
    $data= StringSplit($lines[$i], " ",0)

  ;Now $data holds each item.
  ;$data[1] is the ID. $data[0] is the HDD size.
  ;$data[2] to $data[0(-1)] is the game title data - you would need to reconstruct it:
    $gameName="";Clear variable first.
    For $i = 2 to ($data[0]-1) Step +1
        $gameName=$gameName+$data[$i]
    Next

  ;Should have all we need. Put into an array, or do with what we need. In this case, just output info.
    ConsoleWrite("ID      = " & $data[1] & @CR)
    ConsoleWrite("Name = " & $gameName & @CR)
    ConsoleWrite("HDD   = " & $data[0] & @CR & ---------------------------- & @CR)

Next
Edited by MrBeatnik

Please correct me if I am wrong in any of my posts. I like learning from my mistakes too.

Link to comment
Share on other sites

see :D stringsplit!

I read somewhere that all os's now recognize @LF as a line break, not all recognize @CRLF though...Please correct that too someone...also from the helpfile:

Caution if you use the macro @CRLF you are referring to a 2 character string so you will generate extra blanks lines.

is the game title data - you would need to reconstruct it:

Thats what I was doing in the for loop in mine.

#include <String.au3> - Where do you use this?

other than that it looks good!

Link to comment
Share on other sites

see :D stringsplit!

I read somewhere that all os's now recognize @LF as a line break, not all recognize @CRLF though...Please correct that too someone...also from the helpfile:

Caution if you use the macro @CRLF you are referring to a 2 character string so you will generate extra blanks lines.

is the game title data - you would need to reconstruct it:

Thats what I was doing in the for loop in mine.

#include <String.au3> - Where do you use this?

other than that it looks good!

Hehe, sorry didn't read all the posts in between.

Actually yours is a little leaner!

String.au3 is not needed - I made an error there; was thinking of _StringExplode at first I think.

I am a regexp fan - but only because of my PHP days :o

Please correct me if I am wrong in any of my posts. I like learning from my mistakes too.

Link to comment
Share on other sites

First of all, Thanks for your precious help !

I tried :

CODE
#include <String.au3>

#include <Constants.au3>

;Here you use your cmd to get the output of data - contains ID, games, HDD space.

$output = _CMDreturn('\wbfs_win.exe E list')

;Next we want to split the output into lines. Note line 1 will be the "wbfs" info, line 2 would be blank. Game info starts on line 3

$lines = StringSplit($output, @CRLF, 0)

;Starting at line 3, loop through all lines until the last line (total lines defined at $lines[0]).

For $i = 3 to $lines[0] Step +1

;Split the text of each line where there is a space.

$data= StringSplit($lines[$i], " ",0)

;Now $data holds each item.

;$data[1] is the ID. $data[0] is the HDD size.

;$data[2] to $data[0(-1)] is the game title data - you would need to reconstruct it:

$gameName="";Clear variable first.

For $i = 2 to ($data[0]-1) Step +1

$gameName=$gameName+$data[$i]

Next

;Should have all we need. Put into an array, or do with what we need. In this case, just output info.

ConsoleWrite("ID = " & $data[1] & @CR)

ConsoleWrite("Name = " & $gameName & @CR)

ConsoleWrite("HDD = " & $data[0] & @CR & ---------------------------- & @CR)

Next

Func _CMDreturn($sCommand) ; This function returns the output of a DOS command as a string

$cmdreturn = ""

$stream = Run(@ComSpec & " /c " & $sCommand, @SystemDir, @SW_HIDE, $STDERR_MERGED + $STDIN_CHILD)

While 1 ; loop through the return from the command until there is no more

$line = StdoutRead($stream)

If @error Then ExitLoop

$cmdreturn &= $line

WEnd

Return $cmdreturn

EndFunc ;==>_CMDreturn

$apres = StringLeft($result, 5)

ClipPut($result)

Console errors with ConsoleWrite command. Sorry i'm newbie...

Edited by sambalec
Link to comment
Share on other sites

Using my other method with stringbetween, I finish to success my splits :D

CODE
#include <String.au3>

$var = "SXAP52 Guitar Hero: World Tour 3.95G"

$id = StringLeft($var, 6)

Msgbox(0,"Game ID",$id)

$size = StringRight($var, 5)

Msgbox(0,"Game Size",$size)

$name = _StringBetween ($var, $id, $size)

Msgbox(0,"Game Name",$name[0])

Problem now for me is to split all games lines with array....

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