Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8373675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:44:19+00:00 2026-06-09T14:44:19+00:00

I have an mbox file with 7 messages in it. I try to parse

  • 0

I have an mbox file with 7 messages in it. I try to parse it with the following code on the string “From -“. The resulting object is of length 8 even though there are only 7 occurrences of the string. Even though the first occurrence of the string is at the first space on the first line, the parsing seems to include something before that and a print out of the value of the first element is ‘0’ (the remaining elements are the appropriate strings). Why is there an extra element (is it my code of the methods behaviour)?

var fs = require('fs');

// Read in the text file

fs.readFile( '../Data/Inbox 6Msg Mbox.txt', function (err, data) {
  if (err) {
    throw err; 
  }

// Convert file to a string object

  var unParsed = data.toString();

// Split the text into an array of strings where each
// element is a message

  var indivMessages = unParsed.split("From -");
  console.log(indivMessages.length);

});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:44:20+00:00Added an answer on June 9, 2026 at 2:44 pm

    The mistake you’re making is known as a fencepost error. Although you have seven occurrences of the string, this will result in not seven but eight parts in between the occurrences of the string.

    For instance:

    '1|2|3'.split('|')
    

    Returns

    ['1','2','3']
    

    even though the pipe only occurs twice

    Even if I have the pipe as the first character, the resulting array is the same length:

    '||'.split('|')
    

    returns

     ['','','']
    

    The logic is the same, but now '' has replaced '1', '2', and '3'

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have following listener for keyboard ArrowDown event(it's key code is 40 ): window.onload =
Have a look at the following code to find X^y. /* Find exponent in
I have a huge mbox file, with maybe 500 emails in it. It looks
Have the following code. The height is variable so the height of the floating
I have a single spool mbox file that was created with evolution, containing a
Have a look at the following code. The goal here is to return a
have written this little class, which generates a UUID every time an object of
have a nice day. I got problem when trying to create an image from
I'm upgrading from ColdFusion 8 to ColdFusion 9. I have a Java class that
Have converted devise new session from erb to Haml but doens't work, this is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.