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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:14:25+00:00 2026-06-08T10:14:25+00:00

I have a multi-line text input file: If the String Log Number: is present,

  • 0

I have a multi-line text input file: If the String “Log Number:” is present, it is immediately followed by a log number. If the String “Log Number:” is not present, there is no log number in that record. There is ALWAYS the String “Log Date:”. It follows “Log Number:” if present and appears at that position in the file if it does not.

My inputLine comes out of a BufferedReader that’s reading my file line-by-line.

...
if((inputLine.indexOf("Log Number:"))>-1) {
  logNumRecStart = inputLine.indexOf("Log Number:")+12;}
else
  logNumRecStart = 0;
logNumRecEnd = inputLine.indexOf("Log Date:");
...
logNumber = inputLine.substring(logNumRecStart,logNumRecEnd);
...

and when I output the Start and End indeces, here’s a sample of what I get.

49>>>  -0 to 357
50>>>  -0 to 361
51>>>  -0 to 384
52>>>  -371 to 390
53>>>  -315 to 334
54>>>  -325 to 352

Records 49-51 are cases where “Log Number:” does not appear in the input line, and as expected, logNumRecStart is set to 0. Records 52 – 54 do include “Log Number:”, but the index is being set to a negative number, resulting in my substring getting an out-of-bounds exception. Visually inspecting the file demonstrated the presence (or absence) of the test values in the appropriate lines. My logNumRecEnd value is correct in ALL cases.

By counting characters in the source file for inputLine, I’ve verified that if the negative value of logNumRecStart were POSITIVE, it’d be the correct number.

I’m not using lastIndexOf so I have no idea why I’m getting the negative values. Can anyone see something I’m missing or soemthing I need to check that I’ve not mentioned?

  • 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-08T10:14:27+00:00Added an answer on June 8, 2026 at 10:14 am
    if((inputLine.indexOf("Log Number:"))>-1) {
      logNumRecStart = inputLine.indexOf("Log Number:")+12;}
    else
      logNumRecStart = 0;
    logNumRecEnd = inputLine.indexOf("Log Date:");
    ...
    

    This is all correct and is giving you correct values, so your error must be in the … that you left out somewhere.

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

Sidebar

Related Questions

I have a function that outputs a number to a multi-line text field. Currently,
I have a multi-line text view that can get quite large. When the user
I have an input <input> When someone pastes multi-line text into the input, I
Say I have a multi-line text "a\nb\nc"; when I log it, for example with
/* Suppose I have a multi-line comment with hard line-breaks * that are roughly
I received some multi-line data via HTTP and have it in one string. I
I have a simple form with a multi line text control and Ok/Cancel buttons
I have a MySQL table with 2 columns: text : stores a multi-line text
I have a multi line text box like : <asp:TextBox CssClass=txtform ID=txtWhom runat=server Height=78px
I have: Textbox(Multi-line) Panel Different controls inside panel (buttons,textbox) Scenario: I need to add

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.