sambalec Posted April 14, 2009 Share Posted April 14, 2009 (edited) 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 : CODEwbfs 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 April 14, 2009 by sambalec Link to comment Share on other sites More sharing options...
jvanegmond Posted April 14, 2009 Share Posted April 14, 2009 This is an ideal situation for you to learn simple string operations. Look in the help file for: StringSplit StringInStr StringMid StringTrimLeft, StringLeft StringTrimRight, StringRight github.com/jvanegmond Link to comment Share on other sites More sharing options...
sambalec Posted April 14, 2009 Author Share Posted April 14, 2009 (edited) 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 April 14, 2009 by sambalec Link to comment Share on other sites More sharing options...
Mat Posted April 14, 2009 Share Posted April 14, 2009 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 AutoIt Project Listing Link to comment Share on other sites More sharing options...
sambalec Posted April 14, 2009 Author Share Posted April 14, 2009 I don't really understand your code... sry Link to comment Share on other sites More sharing options...
Stilgar Posted April 14, 2009 Share Posted April 14, 2009 Or you using RegEx: $sString = "SXBE52 Guitar Hero Metallica 4.13G" $a = StringRegExp($sString, "[A-Z0-9]+\s(.*?)\s(\d\.\d\d)G",3) _ArrayDisplay($a) jEdit4AutoIt PlanMaker_UDF Link to comment Share on other sites More sharing options...
Mat Posted April 14, 2009 Share Posted April 14, 2009 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]]) AutoIt Project Listing Link to comment Share on other sites More sharing options...
sambalec Posted April 14, 2009 Author Share Posted April 14, 2009 Hm, not easy for me... Regex very hot Link to comment Share on other sites More sharing options...
Mat Posted April 14, 2009 Share Posted April 14, 2009 ?? 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. AutoIt Project Listing Link to comment Share on other sites More sharing options...
MrBeatnik Posted April 14, 2009 Share Posted April 14, 2009 (edited) 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 : CODEwbfs 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 April 14, 2009 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 More sharing options...
Mat Posted April 14, 2009 Share Posted April 14, 2009 see 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! AutoIt Project Listing Link to comment Share on other sites More sharing options...
MrBeatnik Posted April 14, 2009 Share Posted April 14, 2009 see 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 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 More sharing options...
Mat Posted April 14, 2009 Share Posted April 14, 2009 Actually yours is a little leaner!But it doesnt do seperate line, and is not commented like yours, which was probably wy he didn't get it, at least yours you know what your doing! AutoIt Project Listing Link to comment Share on other sites More sharing options...
sambalec Posted April 14, 2009 Author Share Posted April 14, 2009 (edited) 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 April 14, 2009 by sambalec Link to comment Share on other sites More sharing options...
sambalec Posted April 14, 2009 Author Share Posted April 14, 2009 Using my other method with stringbetween, I finish to success my splits 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 More sharing options...
sambalec Posted April 15, 2009 Author Share Posted April 15, 2009 up Link to comment Share on other sites More sharing options...
sambalec Posted April 15, 2009 Author Share Posted April 15, 2009 any idea ? Link to comment Share on other sites More sharing options...
Mat Posted April 15, 2009 Share Posted April 15, 2009 (edited) Yes, don't bump a topic before your 24 hours, and read through the topic, paying particular attention to the lovely code by one mrbeatnik.#669489 Edited April 15, 2009 by mdiesel AutoIt Project Listing Link to comment Share on other sites More sharing options...
sambalec Posted April 15, 2009 Author Share Posted April 15, 2009 sure ! ... but i don't know how to choose lines on strings var ... Link to comment Share on other sites More sharing options...
jvanegmond Posted April 15, 2009 Share Posted April 15, 2009 I hate that problem sometimes too. When I don't know something I keep searching until I figure it out. github.com/jvanegmond Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now