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 8775633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:51:14+00:00 2026-06-13T18:51:14+00:00

I am problem with using === to compare string I get whole data from

  • 0

I am problem with using === to compare string
I get whole data from text file and split value line by line with (‘\n’)
like readLine() in java
and want to find string “SECTION” but can’t find.

when i put

if(contents[i] === "SECTION") {
    alert("This is section");
}

no alert! I am sure text file have word “SECTION”

but

if (contents[i].match("SECTION)) 

is work.

any suggestion ? thanks


javascript

function readFile (evt) {
var files = evt.target.files;
    if (files) {
        for (var i=0, f; f=files[i]; i++) {
            var file = files[i];           
            var reader = new FileReader();
            reader.onload = function() { 
                var contents = [];
                contents = this.result.split("\n");
                    for (var i = 0; i < contents.length; i++) {
                        if(contents[i] === "SECTION") {
                            alert("This is section");
                        }
                        document.getElementById('textArea').innerHTML +=contents[i];
                    }
            }
            reader.readAsText(file);
        }
    }
}
  • 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-13T18:51:15+00:00Added an answer on June 13, 2026 at 6:51 pm

    There is a bit of weirdness in your code, but:

    var contents = [];
    contents = this.result.split("\n");
    

    There is no need for both lines, the second assignment overwrites the first, so:

    var contents = this.result.split("\n");
    

    .

    for (var i = 0; i < contents.length; i++) {
        if(contents[i] === "SECTION") {
    

    There is no need for === here, though I guess it doesn’t hurt. It may be that there is whitespace around the comparison text, so you might consider either removing whitespace or using a regular expression instead, e.g.:

    var re = /^\s*SECTION\s*$/;
    

    to match the word “SECTION” with optionally any amount of whitespace before and after. If you just want a line that contains the character sequence SECTION, then:

    var re = /\s*SECTION\s*/;
    

    and ignoring case:

    var re = /\s*SECTION\s*/i;
    

    whatever. Then use the test method like:

    for  ( ... ) {
        if (re.test(contents[i])) {
           /* found a section */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get data from file. The file first has three lines of
I'm using a NSDictionary to get a NSString from a plist with the following
Using Ruby 1.9.2 Problem Compare the content, not the results, of two procs. I
I'm having problems using {% ifequal s1 some text %} to compare strings with
Problem Using Director 11.5 and Windows 7, with MouseWheel Xtra (wheelmouse.zip), I have the
The problem: Using ASp.NET MVC for reporting. Given: 1. A report that is tabular
I've got a problem using different layouts for list items in my project. Here
I ran into a problem using Springsource Tool Suite when writing some groovy scripts
I am having problem using mvc:resources in spring 3.1 configuration. Initially i was working
i encountered a problem using the apache commons-net telnet api, and hope you can

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.