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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:31:37+00:00 2026-05-28T01:31:37+00:00

How do I check whether a string fits this format: <number>,<number>,<number> e.g. 3.0, 87546,0.8273456

  • 0

How do I check whether a string fits this format:

<number>,<number>,<number>

e.g.

3.0, 87546,0.8273456

i.e. three comma-separated values that can be parsed as doubles. Sometimes the string will contain something else (e.g. Text,More text,42 or anything, really) and in such a case I just need to ignore it and move on to parsing the next string.

Right now I just try to parse the string as if it fits the expected format, and catch any resulting exception. What is a smarter and less expensive way of doing this? Hopefully without throwing/catching exceptions?

        String[] parsedLine = line.trim().split(",");
        if (parsedLine.length == 3) {
            try {
                xCoordinate = Double.parseDouble(parsedLine[0]);
                yCoordinate = Double.parseDouble(parsedLine[1]);
                groundElevation = Double.parseDouble(parsedLine[2]);
            } catch (NumberFormatException nfe) {
                //This line does not contain numbers exclusively. 
                //Assume it's a header/comment.
                //Do nothing.
            }
        } else {
            //This is not in the expected x,y,z format. 
            //Assume it's a header/comment.
            //Do nothing.
        }
  • 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-05-28T01:31:38+00:00Added an answer on May 28, 2026 at 1:31 am

    What you have right now is probably the most bullet-proof (and in my view the easiest to understand) implementation possible.

    I wouldn’t change it, unless I had specific evidence from the profiler that it’s an overall bottleneck (either in terms of CPU usage, or the amount of garbage created).

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

Sidebar

Related Questions

How can you check whether a string is convertible to an int? Let's say
I need an simple way to check whether a string that is sent to
How can I check whether a string represents a long, a double, or just
Consider a JavaScript method that needs to check whether a given string is in
I want to check whether there is string starting from number and then optional
My question is: can I check whether a variable (string or int/double type) or
I want to check whether a string contains any of the substrings that I
How can i use Pattern.compile to check whether a string contains @. Something like
i want to check whether string present .png , .pdf , .html for that
How can I check whether a given string contains a certain substring, using Perl?

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.