Sign in to follow this  
Followers 0
Tacticious

Text Manipulation

7 posts in this topic

#1 ·  Posted (edited)

Hello all,

I'm trying to do a very basic read of a text file. I would like to break the initial text variable into an array, delimited by line returns. From there, I'd like to break the line variable in the array into a sub-array, delimited by spaces. After that is done I'll be left with an array structure like so:

line[0]

space[0]

1:1

space[1]

something;somethingelse;text;blah;

line[1]

space[0]

1:2

space[1]

moretext;randomstuff;etc;

So, I guess I started off a little backwards. I simply want to manipulate the latter values of each array/sub-array. So in the above example, all I'm looking for is the "something;somethingelse;text;blah;" portion. I don't need an example or snippet (although they are nice), I just need to know what the function is named. I've searched, but without even knowing the function name, it's hard to find. I know in PHP it'd be explode...

My ultimate goal, if anyone is interested in possibly suggesting an easier way to do this, is pretty simple:

I have a log file, it can change at random times. Sometimes every half a second, sometimes once in ten minutes. Currently, I initially open the file and check the file size. I check the file size every half-second. If it's grown, I re-read the file into a variable for manipulation. After that is when the above takes place. Although, I have one grey area I have not figured out in my mind, yet. I need to figure out how to not re-act on everything. So, if it makes sense at all, I need to disregard everything I previously loaded into the variable. Example:

Old text file:

1:1 a;b;c;d

1:2 a;b;c;d

1:3 a;b;c;d

New text file:

1:1 a;b;c;d

1:2 a;b;c;d

1:3 a;b;c;d

1:4 a;b;c;d

How can I disregard everything previously loaded, and only act upon the new changes, thus only giving me:

1:4 a;b;c;d

Once that's figured out, I just want to see whats in the "a;b;c;d" portion, and actually I only want to see if the first part of it is "say". If it is, then I will continue on that portion and act. The raw data would look similar to this:

1725:26 say;0ef71605009e2c59ada9ec3db1b7b22a;2;(HaRm)FOKA;Test

In this example, I'd act because the first part of the block delimited by semicolons is indeed "say". I'd then get the hash directly after the say, disregard the "2", get the name, and the text said (in this case, "Test").

If there is an easier way than looping through the text and breaking it into arrays, I'm all for it. Otherwise, just giving me the name of the function to "explode" strings into arrays based on a delimiter would be awesome and greatly appreciated ;)

Edited by Tacticious

Share this post


Link to post
Share on other sites



Perhaps this is the function you're looking for, Function StringSplit

Perfect! Thanks a lot ;)

If you've got a minute, are you able to tell me if my concept would be correct? Or is there an easier way than looping through the string and breaking it into arrays? If you're busy, that's fine as well, you're response was appreciated :evil:

Share this post


Link to post
Share on other sites

Well I have a lot more time than coding skills.. but I'm sure you'll get help from of the very talented coders here..


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

I'll just use the line number to determine what's already been parsed. Thanks for the help.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I'm just getting into arrays, so I know I probably can't help much, in fact I was ready to quit reading your first thinking I wouldn't be able to help at all, until I saw the PHP explode part. I know enough about this that explode and StringSplit are similar, but Good Luck with your endeavor.

Edited by snowmaker

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

Some ideas..

Maybe for comparing files/results you should try comparing the number of lines in the file rather than directly comparing lines. You can only do this if you're pretty sure that the old (already known) part of the log file isn't going to change.

Example: This will give you the total number of lines ($file should be the contents of the log file)

$countNL = StringRegExp($file, '\n', 4)
$countNL = UBound($countNL)+1

As for matching "say" or whatever you want.. that's defiantly a job for regular expressions

$test = '1725:26 say;0ef71605009e2c59ada9ec3db1b7b22a;2;(HaRm)FOKA;Test'
If StringRegExp($test, '^.{0,10}say;', 0) Then
    MsgBox(0,'','Match')
Else
    MsgBox(0,'','No Match')
EndIf

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  
Followers 0