Jump to content

Text Manipulation

Recommended Posts

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:











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

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.

Link to comment
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,'','No Match')
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

  • Recently Browsing   0 members

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