Sign in to follow this  
Followers 0
JohnBailey

Search String in Position

23 posts in this topic

#1 ·  Posted (edited)

How do I search for text in a particular position in a row. I know FileRead will get the row but how do I say search after x amount of characters.

For instance,

06/15/2007             06/18/2007               Cumulative

That is the text (Row 9) in my file I want to search. However, I need to check that second date against the current date. Both dates change so I can't use _StringBetween. I know the string I want starts at 109 and ends at 119

Edited by JohnBailey

A decision is a powerful thing

Share this post


Link to post
Share on other sites



The following seems to be my answer, but this method is limited and seems inefficient

FileOpen($filetoRead,0)
ConsoleWrite('Line:       '&FileReadLine($filetoRead,9)&@CRLF)
Local $StringBetween = _StringBetween (FileReadLine($filetoRead,9),'               ','                C')
Local $answerp1 = StringTrimLeft(FileReadLine($filetoRead,9),108)
Local $answerp2 = StringTrimRight($answerp1,26)
ConsoleWrite('Amount:       '&StringLen('                Cumulative')&@CRLF)
ConsoleWrite('Check Date: '&$answerp2&@CRLF)

A decision is a powerful thing

Share this post


Link to post
Share on other sites

How do I search for text in a particular position in a row. I know FileRead will get the row but how do I say search after x amount of characters.

For instance,

06/15/2007             06/18/2007               Cumulative

That is the text (Row 9) in my file I want to search. However, I need to check that second date against the current date. Both dates change so I can't use _StringBetween. I know the string I want starts at 109 and ends at 119

#include <array.au3>
$string = "                   06/15/2007               06/18/2007                Cumulative    "
$pattern = '^\s*([^\s]*)\s*([^\s]*)\s*([^\s]*)\s*$'

$values = StringRegExp($string,$pattern,1)

_ArrayDisplay($values)

Then search in the row you need.


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

WOW!!!! Thank you!!!! WAAAAAAAY COOL

I don't really understand what the below means though. I'm reading the Manual, but I'm still not understanding. I don't want to regurgitate this info every time.

$pattern = '^\s*([^\s]*)\s*([^\s]*)\s*([^\s]*)\s*$'

EDIT: wording

Edited by JohnBailey

A decision is a powerful thing

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

WOW!!!! Thank you!!!! WAAAAAAAY COOL

I don't really understand what the below means though. I'm reading the Manual, but I'm still not understanding. I don't want to regurgitate this info every time.

$pattern = '^\s*([^\s]*)\s*([^\s]*)\s*([^\s]*)\s*$'

EDIT: wording

it's a regular expression. See here: http://www.regular-expressions.info/tutorial.html

The expression '^\s*([^\s]*)\s*([^\s]*)\s*([^\s]*)\s*$' means:

^\s* = any whitespace (space, tabs, etc.)

([^\s]*) = any NON-whitespace AND remember

etc.

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

sweeet site and thanks for the explanation! This is so helpful! My previous methods totally sucked


A decision is a powerful thing

Share this post


Link to post
Share on other sites

That is a really great site! I'm passing it on to some buddies of mine that will probably appreciate it and use the info right away!


A decision is a powerful thing

Share this post


Link to post
Share on other sites

Ok, I'm not getting this...

Here's what I'm trying to break into four separate rows

BILL WILDS                      9,700.48               610,633.74                     1.11

Doing the following only gets me "BILL" in the array[0]. Why?

Local $StringtoBreak = $fileArray[12]
ConsoleWrite('String to Break:   '&$StringtoBreak&@CRLF)
Local $pattern = '^\s*([^\s]*[^\s]*)'
Local $BroketoColumns = StringRegExp($StringtoBreak,$pattern,1)
If @error Then MsgBox(0,'Error with StringRegExp',@error&'   '&@extended)
    
_ArrayDisplay($BroketoColumns)

Additionally, I can't seem to find what $ means


A decision is a powerful thing

Share this post


Link to post
Share on other sites

Ok, I'm not getting this...

Here's what I'm trying to break into four separate rows

BILL WILDS                      9,700.48               610,633.74                     1.11

Doing the following only gets me "BILL" in the array[0]. Why?

c2--><!--TG9jYWwgJiMwMzY7U3RyaW5ndG9CcmVhayA9ICYjMDM2O2ZpbGVBcnJheVsxMl0KQ29uc29sZVdyaXRlKCYjMzk7U3RyaW5nIHRv
IEJyZWFrOiAgICYjMzk7JmFtcDsmIzAzNjtTdHJpbmd0b0JyZWFrJmFtcDtAQ1JMRikKTG9jYWwgJiMwMzY7cGF0dGVybiA9ICYj
Mzk7XiYjMDkyO3MqKFteJiMwOTI7c10qW14mIzA5MjtzXSopJiMzOTsKTG9jYWwgJiMwMzY7QnJva2V0b0NvbHVtbnMgPSBTdHJp
bmdSZWdFeHAoJiMwMzY7U3RyaW5ndG9CcmVhaywmIzAzNjtwYXR0ZXJuLDEpCklmIEBlcnJvciBUaGVuIE1zZ0JveCgwLCYjMzk7
RXJyb3Igd2l0aCBTdHJpbmdSZWdFeHAmIzM5OyxAZXJyb3ImYW1wOyYjMzk7ICAgJiMzOTsmYW1wO0BleHRlbmRlZCkKCQpfQXJy
YXlEaXNwbGF5KCYjMDM2O0Jyb2tldG9Db2x1bW5zKQ==--><!--eg

Additionally, I can't seem to find what $ means

$ = end of string.

Do you have a file example, something that shows a whole list of information?


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

An example of me being lazy :rolleyes:

#include <array.au3>

$sString = "                                    BILL WILDS                        9,700.48               610,633.74                      1.11"
$sPattern = '(?s)(?i)\s+(\w+\s\w*|.*?)(?m:$|\s)'
$aArray = StringRegExp($sString, $sPattern, 3)
_ArrayDisplay($aArray)

Edit:

Ugh... what the hell is wrong with the code after editing or comments?

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Maybe you should try out StringTrimLeft/StringTrimRight, StringInStr, StringLeft/StringRight etc. functions and see if you can work something out like that(getting a hold of using strings is a good knowledge to have imo. :rolleyes:)

Edited by FreeFry

Share this post


Link to post
Share on other sites

Ugh... what the hell is wrong with the code after editing or comments?

Yeah, the code looks almost like if it have been encrypted or something :| // offtopic

Share this post


Link to post
Share on other sites

An example of me being lazy :rolleyes:

c2--><!--I2luY2x1ZGUgJmx0O2FycmF5LmF1MyZndDsKCiYjMDM2O3NTdHJpbmcgPSAmcXVvdDsgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICBCSUxMIFdJTERTICAgICAgICAgICAgICAgICAgICAgICAgOSw3MDAuNDggICAgICAgICAgICAgICA2MTAsNjMz
Ljc0ICAgICAgICAgICAgICAgICAgICAgIDEuMTEmcXVvdDsKJiMwMzY7c1BhdHRlcm4gPSAmIzM5Oyg/cykoP2kpJiMwOTI7cysoJiMwOTI7dysmIzA5MjtzJiMwOTI7dyp8Lio/KSg/bTomIzAzNjt8JiMwOTI7cykmIzM5OwomIzAzNjthQXJyYXkgPSBTdHJpbmdSZWdFeHAoJiMwMzY7c1N0cmluZywgJiMwMzY7c1Bh
dHRlcm4sIDMpCl9BcnJheURpc3BsYXkoJiMwMzY7YUFycmF5KQ==--><!--eg

Edit:

Ugh... what the hell is wrong with the code after editing or comments?

seems to be a bug after the forum software upgrade.

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

Freefly, I originally was achieving my goal using the String functions you mentioned. However, doing so isn't dynamic (at least how I was doing it).

Smoke_N, that's awesome. I'm still not entirely understanding the differences between all the symbols. I went to http://e-texteditor.com/blog/2007/regular_...ssions_tutorial but I'm still confused. I'm not really picking this up well at all.


A decision is a powerful thing

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

seems to be a bug after the forum software upgrade.

Let's bow down to Jon, and pray for him to fix it! :rambo:

Freefly, I originally was achieving my goal using the String functions you mentioned. However, doing so isn't dynamic (at least how I was doing it).

Hmm, well I think you probably could make it dynamic, you just have to make it detect what kind of content the row contains. Or try to understand the RegExp stuff

Edit:

damnit :rolleyes: my name is FreeFry xD

Edited by FreeFry

Share this post


Link to post
Share on other sites

Let's bow down to Jon, and pray for him to fix it! :rolleyes:

Hmm, well I think you probably could make it dynamic, you just have to make it detect what kind of content the row contains. Or try to understand the RegExp stuff

huh?


A decision is a powerful thing

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

Hmm, I was under the influence that

" 06/15/2007 06/18/2007 Cumulative"

and

" BILL WILDS 9,700.48 610,633.74 1.11"

was two different rows, and that you might somehow identify what type of "data" the row contains, and make a dynamic, yet in a way, static detection system, and that way get what you want from the rows

Edit:

whops

Edited by FreeFry

Share this post


Link to post
Share on other sites

Hmm, I was under the influence that

" 06/15/2007 06/18/2007 Cumulative"

and

" BILL WILDS 9,700.48 610,633.74 1.11"

was two different rows, and that you might somehow what type of "data" the row contains, and make a dynamic, yet in a way, static detection system, and that way get what you want from the rows

:rolleyes:

Are you sure that influence didn't stem over till the 20th?


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Hmm, I was under the influence that

" 06/15/2007 06/18/2007 Cumulative"

and

" BILL WILDS 9,700.48 610,633.74 1.11"

was two different rows, and that you might somehow what type of "data" the row contains, and make a dynamic, yet in a way, static detection system, and that way get what you want from the rows

yeah I am just trying to make a var for each "column" in each row, so I can use it.

I was confused on what you meant by the Jon stuff.


A decision is a powerful thing

Share this post


Link to post
Share on other sites

:rolleyes:

Are you sure that influence didn't stem over till the 20th?

woot :x

yeah I am just trying to make a var for each "column" in each row, so I can use it.

I was confused on what you meant by the Jon stuff.

Yes, sorry, I posted right after your post, I was responding to Sm0ke_N's post about the forum bug, I edited my post to make it a little clearer. :rambo: I'm a little bit tired now doh xD

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  
Followers 0