Jump to content
Sign in to follow this  
Jack023

make array from textfile and split them.

Recommended Posts

Jack023

Hey all,

I have some information in a textfile listed with:

information1:information2

information3:information4

etc...

now i want make a a dimensiol array array[0][0]

then second line 

array[1][1].

This is possible i think?

Could somebody help me , let we say the textfile is named: information.txt

Thanks in advance

Share this post


Link to post
Share on other sites
Jack023

Can't edit it, but i want: array [0] is nothing

Information1:information2

I want information1 in array[1] and ifirmation 2 in array[2]

Information3:Information4

Informatiom3 in array[3] etc

But not the ' : ' symbol

All read from a textfile!

Thanks in advance ,

Share this post


Link to post
Share on other sites
jdelaney

Here:

#include <Array.au3>
$sString = FileRead(@DesktopDir & "\some.txt")
$aData = StringSplit($sString, @LF & ":")

; Remove @CR's
For $i = 1 To UBound($aData) - 1
    $aData[$i] = StringStripCR($aData[$i])
Next
_ArrayDisplay($aData)

Returns:

[0]|4
[1]|information1
[2]|information2
[3]|information3
[4]|information4
 

Where desktop file = some.txt contains:

information1:information2
information3:information4

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
jdelaney

or, returning a base 0 array:

#include <Array.au3>
$sString = FileRead(@DesktopDir & "\some.txt")
;~ $aData = StringSplit($sString, @LF & ":")

; Remove @CR's
;~ For $i = 1 To UBound($aData) - 1
;~  $aData[$i] = StringStripCR($aData[$i])
;~ Next
;~ _ArrayDisplay($aData)

$aData = StringRegExp($sString,"[^:\v]+",3)
_ArrayDisplay($aData)

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
Jack023

Perfect ! Thanks and i will look if i can complete it ;)

Share this post


Link to post
Share on other sites
czardas

Can be done with >_CSVSplit First read file and then pass the data to the function with the delimiter changed to colon. That's if you want  a 2D array. I'm not sure what a a dimensiol array array is is. Maybe it's not what you want.

Oops wrong function name - changed.

Edited by czardas

Share this post


Link to post
Share on other sites
jchd

I'm not sure what a a dimensiol array array is is.

How do you call these pink pills in your area? :think:

 

Maybe it's not what you want.

Sure!

  • Like 1

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
czardas

How do you call these pink pills in your area? :think:

 

I don't know if I'm seeing double, or it's the pills. I mean: even the indices have been doubled. >_< I thought the OP wanted a 2D array.

Edited by czardas

Share this post


Link to post
Share on other sites
Jack023

#include <Array.au3>


;array read

$sString = FileRead(@DesktopDir & "\5faccs.txt")
$aData = StringSplit($sString, @LF & ":")

; Remove @CR's
For $i = 1 To UBound($aData) - 1
    $aData[$i] = StringStripCR($aData[$i])
Next

fixed it, only need help with my loop, but its a private script , so i dont want bring it in public!

If someone can add me at skype: jack.jack023

i would really appreciate that !

Edited by Jack023

Share this post


Link to post
Share on other sites
czardas

Where did you put the message box? When the loop has finished, $i is greater than the maximum index of the array. If you also then add 1, $i will be greater by 2 counts. You should get an error about array dimension range exceeded. Put the msgbox inside the loop and do not add 1.


Oh you deleted your question. Now my responce makes no sense.

Edited by czardas

Share this post


Link to post
Share on other sites
Jack023

well thats not the point, i fixed that but i don't want to put my whole script here what i mean ;)

if someone can add me :)

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  

×