Jump to content
Sign in to follow this  
computergroove

Breaking apart data in an ini file

Recommended Posts

computergroove

I have several strings:

1, John, Smith, john.smith@gmail.com,12/12/77,PO Box 592,Caledonia,MI,49316

2, Paul, Beck, Paulbeck@hotmail.com, 5/8/65,210 Short St, Grand Rapids, MI 49508

3.....

What is the procedure to take this data from 'settings.ini' and choose a line and assign each of these coma seperated items to a value in my script? I.E.

$Number = '1'

$FirstName = 'John'

$LastName = 'Smith'

$Email = 'john.smith@gmail.com'

$DOB = '12/12/77'

$Address = 'PO Box 592'

$City = 'Caledonia'

$State = 'MI'

$Zip = '49316'

I want to run each line in settings.ini individually through my script and then begin processing the next line.


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites
water

Use StringSplit to fill an array with teh required data.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
kspratik

U can organize ur Ini file in this way

[First Name]

firstname="Prateek"

[Last Name]

last Name="Kumar"

[Email Id]

emailid="xyz@gmail.com"

[DOB]

dob="14/06/1990"

[Address]

add="abc"

[City]

city="Banglore"

[state]

state="karnataka"

[Zip]

zip="123...."

Now use IniRead($filePath & $fileName,"Section name"," sub field of that section","default value which u want")

ex :

$FirstName=IniRead($filePath & $fileName,"First Name","firstname","")

value of $FirstName=Prateek

If u want to process each section one by one then organize ur ini file in this way

[Person1]

firstname=

lastname=

emai id=

dob=

address=

city=

state=

zip=

for next person

[Person2]

repeat the same thing

I think u will get ur solution from this.

Share this post


Link to post
Share on other sites
UEZ

I wouldn't use here ini functionality here rather 2D arrays where you store all the data in.

It is easier to handle an array than ini files whereas ini files are restricted to 32kb due to compatibility reasons.

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
computergroove

I wouldn't use here ini functionality here rather 2D arrays where you store all the data in.

It is easier to handle an array than ini files whereas ini files are restricted to 32kb due to compatibility reasons.

Br,

UEZ

I am a bit confused by this. By 2D array do you mean place the data directly in my script rather than use an ini file? Can you show me an example based on my original post?


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites
water

UEZ proposes to read the data from your file to an array.

As the file is in CSV (comma separated values) format you could use this written bei ProgAndy to read the file and create a 2D-array.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
UEZ

Assumption: your strings from your 1st post are in a file called settings.ini but without leading line numbers:

#include <Array.au3>

Global $aS = StringSplitW(FileRead(@ScriptDir & "settings.ini"), ",")
_ArrayDisplay($aS)

This will read the content of the settings.ini file and create a 2D array which can be processed appropriately.

StringSplitW() can be found here:

You can easily write back the 2D array to a file again.

I hope this helps you.

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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  

×