Jump to content

Recommended Posts

Posted

Ok say I have a file that contains:

five|ten|three|five|six|ten|five

I want to count how many of each there are between the delimiter: "|". I dont know where they are or what they are though. I just cant think how to make a function for this.

the function would have to read me back something like,

five=3,ten=2 three=1 six=1

I hope you guys know what I mean.

Thanks a bunch

Check out ConsultingJoe.com
Posted (edited)

use empty array.

while reading file use loop to tokenize it concerning "|" delimiter.

check against array if read token is already there.

if "Yes" increase value for the proper item of the array.

if "No" add new item with value "1".

should work :)

P.S.

"token" mentioned above is string you are looking for, that is "five", "ten", "six" etc.

Edited by 3telnick
Posted (edited)

something like this???

$String="five|ten|three|five|six|ten|five"

$Split=StringSplit($String,"|",0)

$line=""

For $z = 1 to $Split[0]

$array = StringSplit($String, $Split[$z], 1)

if Stringinstr($line,$Split[$z]) = 0 then $line=$line & $Split[$z] & " = " & $array[0]-1 & ", "

next

MsgBox(0,"",$line)

Count_Splits.au3

Edited by Rick

Who needs puzzles when we have AutoIt!!

Posted

something like this???

$String="five|ten|three|five|six|ten|five"

$Split=StringSplit($String,"|",0)

$line=""

For $z = 1 to $Split[0]

$array = StringSplit($String, $Split[$z], 1)

if Stringinstr($line,$Split[$z]) = 0 then $line=$line & $Split[$z] & " = " & $array[0]-1 & ", "

next

MsgBox(0,"",$line)

Thanks 3telnick and Rich. @Rick that was right on, thanks. I just kept getting confused when I was trying to do it.

Check out ConsultingJoe.com

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
  • Recently Browsing   0 members

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