Jump to content

Search & replace string character without loops


Recommended Posts

Hello,

I have an acquired string (not array) that has a repeatable pattern:

2014062414:17:50.401B      0E     0E 2014062414:17:54.603      0E     0E 2014062414:17:55.648D      0E     0E 2014062414:17:55.862A     0E     0E 2014062414:57:10.786     0U     0U 2014062414:57:11.841      0U     0U 2014062414:57:18.112     34  11111  2014062414:57:19.157     34  11111  ....

This is an array made up from a time-stamp and certain values (settings). The aim is to convert it to a 2D array and each row will be a 4 element 1D array in the following format: 2014062414:17:50.401|B|0E|0E| where "|" is placed to denote a different cell.

The problem is that that the array has 1,000,000 time-stamps & set of settings ie a few million characters, hence using loops to manipulate it make my pc run out of memory!

In addition the second setting "B" in "2014062414:17:50.401B      0E     0E", sometimes it appears, sometimes its another word character (ie A) or sometimes its a "space" character, always attached to the time-stamp. I am looking for a way to create a space between the time-stamp & the character if present in order to, further down the line, create a column with the word characters.

Any suggestions?

 

Thank you in advance

Link to comment

If time isn't important, the easiest thing would probably to break it into two parts. First find and replace, then do the rest of your processing. However it doesn't sound like you have a really big file (maybe a few 10s of MB) so maybe if you can take a screenshot of your core loop we could provide some more specific feedback on how to avoid data copies.

If you can't, then drjd's recommendation is the right one with two additions:
-If it wasn't clear from his post, a lot of the string copies don't actually produce output strings if you don't wire them. So for something like match pattern (I think thats one of the ones where it works) you can say "look through my 10 MB string for '|'" and it won't actually allocate two new X MB strings -- it will just tell you "I found it at index N".
-If the mystery string is in a file already, you can read it in line by line (if it has lines) or chunk by chunk (it looks like each chunk is a fixed size, but even if it isn't you can still do this you just have to be sure to use the leftovers).

 

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.