Jump to content

Breaking apart data in an ini file


Recommended Posts

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

Link to comment
Share on other sites

Use StringSplit to fill an array with teh required data.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...