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

  • Home
  • SEARCH
  • 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 7912223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:32:45+00:00 2026-06-03T13:32:45+00:00

I have a flat file that I’m trying to scrub for import into a

  • 0

I have a flat file that I’m trying to scrub for import into a database. The layout is inconsistent, but always consists of a fieldname (variable length text but ALWAYS one of 9 words or phrases) followed by a freeform text field (variable length up to 1024 bytes). I need to extract the 1024 byte field, and arrange them into columns across fieldnames.

Input File:

 foo-01 bunches of data
 foo bar01 more bunches of data including a bunch of notes
 foo-01 lots of data lives in this field
 foo18 monday notes 
    ...etc.

Output File – delimited, spaces trimmed

 foo-01;foo bar 01;foo18                 (<-- header row)
 bunches of data; more bunches of data including a bunch of notes; ;
 lots of data lives in this field; ; notes

My strategy is this: Read each line. If the line starts with one of the nine fieldnames, I write a substring (first character after the fieldname through the last character in the line – spaces trimmed) to a deliminted flat file in the appropriate column position.

This code works,

 if(inputLine.startsWith("foo-01"))
 {
      String lineVal = inputLine.trim();
      int lVLen = lineVal.length();
      String outVal  = lineVal.substring(17,lVLen);
      String outValTrim = outVal.trim();
      System.out.println(evalVal+" "+inputLine+" "+outValTrim);
  }
  else 
  ...etc...

But raises questions.

Consider:

 String outValTrim = inputLine.trim().substring(17,inputLine.trim().length()).trim();
  • What is the maximum number of methods that I can use? e.g., foo =
    Stringmethod1.Stringmethod2.StringMethod3()

  • Is there a rule for the order of the methods in the statement?

  • What are the best practices for combining methods in one statement? I
    feel it’s less human-readable, and I’m not sure about efficiency.

  • 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-03T13:32:46+00:00Added an answer on June 3, 2026 at 1:32 pm

    The maximum size for a method is 64K, you can’t use more method than this. You may also find that you don’t need to chain as many methods as you might think.

    String outValTrim = inputLine.trim().substring(17).trim()
    

    I suspect the first trim() is not correct…

    What is best practice is to make the code are readable and easy to understand as possible.

    Efficiency is rarely the most important issues and unless you can prove e.g. by using a profiler, that this is the cause of a problem for you, stick with readability.

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

Sidebar

Related Questions

I have a txt file that I’m trying to import as flat file into
I have a flat data file that I need to import into my SQL
I have simple SSIS package where I import data from flat file into SQL
I have a flat file that is pipe delimited and an database table. I
Essentially, I have to get a flat file into a database. The flat files
I am trying to import data from a utf-8 encoded flat file into SQL
I have a flat file that consists of the following structure: A1 B1 C1
I have an old Access database that is basically one flat file. I want
I have a rather complex Flat File that I'm trying to parse using SSIS.
I am supporting an ETL process that transforms flat-file inputs into a SqlServer database

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.