Jump to content

StringSplit


Recommended Posts

I need to extract the date from an .ini file and then store it. the date i need to extract is in this format.

Text;~date+Text;

It is surrounded by text and ; then a ~, then a + sign then text again. I have no idea how to string split that outta there.

any help?

Link to comment
Share on other sites

try this...

$start = stringinstr($string,"~") + 1 ;this is the position in the string where the date begins

$end = stringinstr($string,"+") ;this is where it ends

$count = $end - $start ;this creates your count parameter for the stringmid() function

$date = stringmid($string,$start,$count)

Link to comment
Share on other sites

I need to extract the date from an .ini file and then store it. the date i need to extract is in this format.

Text;~date+Text;

It is surrounded by text and ; then a ~, then a + sign then text again. I have no idea how to string split that outta there.

any help?

You could use StringRegExp().
Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt
Link to comment
Share on other sites

Thanks all, maybe I should fully explain my problem before i hurt myself trying to figure this out.

I use INIWrite() to write data to an ini everytime i click a button. its getting the data from an external app and here's what the iniwrite() looks like:

INIWrite(@ScriptDir & "\temp.ini", "section1", $text, IniRead(@ScriptDir & "\temp.ini", "section1", text, "") & $text & ";")

my ini file is getting overwritten in a place i dont want it to, in this case the date the ini was written is getting overwritten by the above line.

here's an example of how the ini may look before getting overwritten:

[section1]

key=text1;text2;text3;date+On;

somehow the iniwrite line above is overwriting the date and i dont want the date to ever be overwritten. so how can i extract the date and then once that line has been executed it will put that whole line (key and value) back into section1?

i know this post is confusing, as i am a retard and cant even understand it myself.

Link to comment
Share on other sites

sounds like Airwolf123's StringRegExp() will be your better bet... but I'll have to bow out of this post and yield to more experienced users, since I've never used it

Link to comment
Share on other sites

Thanks all, maybe I should fully explain my problem before i hurt myself trying to figure this out.

I use INIWrite() to write data to an ini everytime i click a button. its getting the data from an external app and here's what the iniwrite() looks like:

INIWrite(@ScriptDir & "\temp.ini", "section1", $text, IniRead(@ScriptDir & "\temp.ini", "section1", text, "") & $text & ";")

my ini file is getting overwritten in a place i dont want it to, in this case the date the ini was written is getting overwritten by the above line.

here's an example of how the ini may look before getting overwritten:

[section1]

key=text1;text2;text3;date+On;

somehow the iniwrite line above is overwriting the date and i dont want the date to ever be overwritten. so how can i extract the date and then once that line has been executed it will put that whole line (key and value) back into section1?

i know this post is confusing, as i am a retard and cant even understand it myself.

$string = "text1;text2;text3;date+On;"
$result = StringRegExp($string, "(.*?);(.*?);(.*?);(.*?);", 3)

$NumElements = Ubound($result)
ConsoleWrite("Number of matches: " & $NumElements & @CRLF)
For $X = 0 to $NumElements-1
    ConsoleWrite($result[$X] & @CRLF)
Next
Link to comment
Share on other sites

I need to extract the date from an .ini file and then store it. the date i need to extract is in this format.

Text;~date+Text;

It is surrounded by text and ; then a ~, then a + sign then text again. I have no idea how to string split that outta there.

any help?

$string = "Text;~date+Text;"
$result = StringRegExp($string, ".*?;~(.*?)\+", 3)

$NumElements = Ubound($result)
ConsoleWrite("Number of matches: " & $NumElements & @CRLF)
For $X = 0 to $NumElements-1
    ConsoleWrite($result[$X] & @CRLF)
Next
Link to comment
Share on other sites

Weaponx is a genious with StringRegExp(). :) Follow his example.

The problem with your initial IniWrite is that you were writing to the key that you were reading from... Unless that was your intention - in which case, you'll be forced to read the date and re-inject it into the key value if you do not want it to be changed.

Edited by Airwolf123
Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt
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...