Sign in to follow this  
Followers 0
Jewtus

Replace in array @CRLF

16 posts in this topic

I'm having issues with an table that has a CRLF that I've grabbed using this command

Local $oTable = _IETableGetCollection($oIE, 1)
Local $aTableData = _IETableWriteToArray($oTable,True)

column 3 has a CRLF and then the word NAME: for every row in the array.

I'm trying to figure out how to replace any occurrences of @CRLF"NAME: " with the delimiter |. Any tips?

Share this post


Link to post
Share on other sites



I have been messing with those, but I don't think I understand completely how to execute them:

_ArrayDisplay(StringReplace($aTableData,(@CRLF"Name :"),"|"))

I've tried various iterations of this but every time the search string gives me an error when it gets to the @CRLF. If I put @CRLF in quotes, nothing shows up.

Sorry if this is a dumb question. I'm just getting use to autoit, so some of the more complicated processes I'm trying to do get me very confused.

I was using Powershell to do some of these (saved the array to a file and then ran the following powershell):

$filepath = "C:\Automation\AutoIt\log\example.txt"
$outfile = "C:\Automation\AutoIt\log\outfile.csv"

(Get-Content $filepath -raw) | 
Foreach-Object {$_ -replace "Name: ", "`"|"`
-replace "`n`"", ""`
} | Set-Content $outfile

but I was getting really inconsistent results with powershell. I was hoping I could do this whole thing with autoit.

Share this post


Link to post
Share on other sites

You get this array right?

Local $aTableData = _IETableWriteToArray($oTable,True)

What does it look like?

Create an example if you like or take a screenshot.

Even just give a real text example of the exact contents of each element.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

5b4v1t.jpg

Share this post


Link to post
Share on other sites

I got an error 

For $j = 0 To UBound($aTableData),2) - 1
                                  ^Error

Illegal text at the end of statement (one statement per line)

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

oops I've made the correction now in my first reply - that line should read:

For $j = 0 To UBound($aTableData[$i], 2) - 1
Edited by Jury

Share this post


Link to post
Share on other sites

Error again

For $j = 0 To UBound($aTableData[$i], 2) - 1
For $j = 0 To UBound(^ ERROR

Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded

Share this post


Link to post
Share on other sites

Error again

For $j = 0 To UBound($aTableData[$i], 2) - 1
For $j = 0 To UBound(^ ERROR

Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded

 

That line should be:

For $j = 0 To UBound($aTableData, 2) - 1

Cheers,

sahsanu

1 person likes this

Share this post


Link to post
Share on other sites

That did it!

Thanks!

Jury, if you update it again I'll mark it as solved.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

For $i = 0 To UBound($aTableData, 1) - 1 ; first dimension of array
    For $j = 0 to UBound($aTableData, 2) - 1 ; second dimension of array
    $aTableData[$i][$j] = StringRegExpReplace($aTableData[$i][$j], '(?-s)(?-i)\r?\n\s*NAME\s*:', '|')
    Next
Next
_ArrayDisplay($aTableData)

Edited by Jury

Share this post


Link to post
Share on other sites

What are (?-s) and (?-i)  for ?

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

(?-s)(?-i) is the same as (?-is) and negates s and i options from there on. See options § in help. Pretty useless in this case since both are OFF by default.

r?n can be replaced by R

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Well, not completely useless if you are an old bloke and want constant reminding exactly what any given regEx is doing. :

But thanks for the explanation.

Share this post


Link to post
Share on other sites

jc, my question was not specific enough... saying 'what is it for' I didn't ask for 'what does that mean' but : what is the use of this, except if used in the middle of a pattern to restore default(s)  :)

Share this post


Link to post
Share on other sites

These are regEx Modifiers

I almost always use them to make my regular expressions more explicit and they enable one to modify what a given regEx is doing mid-expression e.g. ignoring the case of letters until you get to a certain point then turning case sensitivity on OR ignoring line returns/carriage returns until a certain point then recognising them again.   

As one of the worlds top experts - Jan Goyvaerts explains:


(?i) Turn on case insensitivity for the remainder of the regular expression. (Older regex flavors may turn it on for the entire regex.) te(?i)st matches teST but not TEST.

(?-i) Turn off case insensitivity for the remainder of the regular expression. (?i)te(?-i)st matches TEst but not TEST.

(?s) Turn on "dot matches newline" for the remainder of the regular expression. (Older regex flavors may turn it on for the entire regex.)

(?-s) Turn off "dot matches newline" for the remainder of the regular expression.

(?m) Caret and dollar match after and before newlines for the remainder of the regular expression. (Older regex flavors may apply this to the entire regex.)

(?-m) Caret and dollar only match at the start and end of the string for the remainder of the regular expression.

(?x) Turn on free-spacing mode to ignore whitespace between regex tokens, and allow # comments.

(?-x) Turn off free-spacing mode.

(?i-sm) Turns on the options "i" and "m", and turns off "s" for the remainder of the regular expression. (Older regex flavors may apply this to the entire regex.)

(?i-sm:regex) Matches the regex inside the span with the options "i" and "m" turned on, and "s" turned off.

1 person likes this

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