Jump to content
Sign in to follow this  
myspacee

Find values in a given string

Recommended Posts

myspacee

hello to all,

i've a script that search for file CRC in a database and return entry if found.

This is typical string:

--------------------------------------------------------------------------------------------

rom ( name "2 - Final Fantasy Crystal Chronicles: My Life as a King (NA).wad" size 44999168 crc DAEEDD76 )

--------------------------------------------------------------------------------------------

need to extract 3 values:

number = '2'

filename = 'Final Fantasy Crystal Chronicles: My Life as a King (NA).wad'

size = '44999168'

anyone can help to extract these info ?

Thank you,

m.

Share this post


Link to post
Share on other sites
99ojo

hello to all,

i've a script that search for file CRC in a database and return entry if found.

This is typical string:

--------------------------------------------------------------------------------------------

rom ( name "2 - Final Fantasy Crystal Chronicles: My Life as a King (NA).wad" size 44999168 crc DAEEDD76 )

--------------------------------------------------------------------------------------------

need to extract 3 values:

number = '2'

filename = 'Final Fantasy Crystal Chronicles: My Life as a King (NA).wad'

size = '44999168'

anyone can help to extract these info ?

Thank you,

m.

Hi,

i bet that some of the StringReg Gurus are jumping the train as well, but try this:

#include <string.au3>
$string = "rom ( name ""2 - Final Fantasy Crystal Chronicles: My Life as a King (NA).wad"" size 44999168 crc DAEEDD76 )"
$number = StringMid ($string, StringInStr ($string, Chr (34)) + 1, 1)
$tempstring = _StringBetween ($string, Chr (34), Chr (34))
$filename = StringTrimLeft ($tempstring [0], 4)
$size = _Stringbetween ($string, "size ", " crc")
MsgBox (0,"", $number & @CRLF & $filename & @CRLF & $size [0])

;-))

Stefan

Edited by 99ojo

Share this post


Link to post
Share on other sites
myspacee

thank you for reply,

but your code often returns only part of number...

read about StringRegExp but don't understand usage.

Anyone can do some example based on my string ?

Thank you for your time,

m.

Share this post


Link to post
Share on other sites
99ojo

thank you for reply,

but your code often returns only part of number...

read about StringRegExp but don't understand usage.

Anyone can do some example based on my string ?

Thank you for your time,

m.

Hi,

then you should post more strings, and not the only one typical string, which seems not as typical as it looks like.

;-))

Stefan

[Edit] Try this for the numbers. I guess the problems are the xx numbers:

$number = StringReplace (StringMid ($string, StringInStr ($string, Chr (34)) + 1, 2), " ", "")

Edited by 99ojo

Share this post


Link to post
Share on other sites
myspacee

Post portion of .dat file:

rom ( name "18 - Gyrostarr (NA).wad" size 40789440 crc DDE38445 )
    rom ( name "19 - Yakuman Wii: Ide Yosuke no Kenkou Mahjong (JP).wad" size 14561536 crc 01D22287 )
    rom ( name "20 - TV Show King (JP).wad" size 41709440 crc 4A378A6B )
    rom ( name "21 - Saikyou Ginsei Shogi (JP).wad" size 25491968 crc C7BA3554 )
    rom ( name "22 - Infinite Bubblewrap at Home Wii (JP).wad" size 41516736 crc 816EA202 )
    rom ( name "23 - Tsuushin Taikyoku: Hayazashi Syogi Sandan (JP).wad" size 21595456 crc D5B1001F )
    rom ( name "24 - Pirates: The Key of Dreams (NA).wad" size 19132288 crc 83077BEF )
    rom ( name "25 - Major League Eating: The Game (NA).wad" size 33810816 crc 0AA4E2A9 )
    rom ( name "26 - Wild West Guns (NA).wad" size 39665792 crc CE84D203 )
    rom ( name "27 - Critter Round-Up (NA).wad" size 33388864 crc AEB444F9 )
    rom ( name "28 - Pong Toss! Frat Party Games (NA).wad" size 19662080 crc CBC8C9E3 )
    rom ( name "29 - Wild West Guns (JP).wad" size 39665088 crc 25AB7D3D )
    rom ( name "30 - Strong Bad's Cool Game for Attractive People - Episode 1: Homestar Ruiner (NA).wad" size 45667456 crc 48AE09AA )
    rom ( name "31 - Helix (NA).wad" size 40616768 crc B49FCB97 )
    rom ( name "32 - My Pokemon Ranch (EU).wad" size 21347904 crc EA440AFC )
    rom ( name "33 - Magnetica Twist (NA).wad" size 19263552 crc 9D7D9450 )
    rom ( name "34 - My Aquarium (NA).wad" size 33471232 crc 25725328 )
    rom ( name "35 - Groovin' Blocks (NA).wad" size 45272640 crc 5FF1B7F5 )
    rom ( name "36 - Star Soldier R (JP).wad" size 24977920 crc B2EB81E7 )
    rom ( name "37 - Strong Bad's Cool Game for Attractive People - Episode 2: Strong Badia the Free (NA).wad" size 45785152 crc 7726C535 )
    rom ( name "38 - Mega Man 9 (NA).wad" size 15929536 crc BC2A8FEE )
    rom ( name "39 - Plaettchen Twist 'n' Paint (NA).wad" size 40376064 crc 7246013A )

thank you for $number correction,

m.

Share this post


Link to post
Share on other sites
AndyG

Hi,

this works with the given DAT-File

#include <File.au3>
#include <String.au3>
$datafile="romdata.dat"

for $i = 1 to _filecountlines($datafile)
$data = filereadline($datafile,$i)
if @error then exitloop
$number =   _stringbetween($data,"name """," -")
$filename=  _stringbetween($data,"- ",""" size")
$size=      _stringbetween($data,"size "," crc")
msgbox(0,"Info:",   "Number:   " & $number[0] & @crlf& _
                "Filename: " & $filename[0] & @crlf& _
                "Size:     " & $size[0])
next

Andy

Edited by AndyG

Share this post


Link to post
Share on other sites
memoryoverflow

Since you asked for RegExe and another reader may stumble upon this thread when searching for "RegExe", here a simple example how to do it:

#include <array.au3>
$sString = 'name "19 - Yakuman Wii: Ide Yosuke no Kenkou Mahjong (JP).wad" size 14561536 crc 01D22287'
$asParts = StringRegExp($sString, 'name\s"(.*?)\s-\s(.*?)"\ssize\s(.*?)\sc.*\z', 3)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $asParts = ' & _ArrayToString($asParts, '; ') & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
You can do it more compact, but that would be more difficult to read for a RegExe rookie. Comparing the example with AutoIt's help will give you the hang of it - and I promise: You'll love it.


(The signature is placed on the back of this page to not disturb the flow of the thread.)

Share this post


Link to post
Share on other sites
myspacee

Thank you all for reply,

RegExe it's Hard to understand, but works like a charm.

thank you,

m.

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.