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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:02:57+00:00 2026-05-26T17:02:57+00:00

I have strings formatted similar to the one below in a Java program. I

  • 0

I have strings formatted similar to the one below in a Java program. I need to get the number out.

Host is up (0.0020s latency).

I need the number between the ‘(‘ and the ‘s’ characters. E.g., I would need the 0.0020 in this example.

  • 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-26T17:02:57+00:00Added an answer on May 26, 2026 at 5:02 pm

    It depends on how “similar” you mean. You could potentially use a regular expression:

    import java.math.BigDecimal;
    import java.util.regex.*;
    
    public class Test {
        public static void main(String args[]) throws Exception {
            Pattern pattern = Pattern.compile("[^(]*\\(([0-9]*\\.[0-9]*)s");        
            String text = "Host is up (0.0020s latency).";
    
            Matcher match = pattern.matcher(text);
            if (match.lookingAt())
            {
                String group = match.group(1);
                System.out.println("Before parsing: " + group);
                BigDecimal value = new BigDecimal(group);
                System.out.println("Parsed: " + value);
            }
            else
            {
                System.out.println("No match");
            }
        }
    }
    

    Quite how specific you want to make your pattern is up to you, of course. This only checks for digits, a dot, then digits after an opening bracket and before an s. You may need to refine it to make the dot optional etc.

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

Sidebar

Related Questions

Suppose I have a large number of strings formatted something like: <tag>blah blahXXXXXblah blah</tag>
I have strings that are formatted as below: Houston, TX - str1 Chicago, IL
So I have a flashobject which I need to pass a formatted DateTime string
I need to create an easy way to split up some strings into formatted
I have a strings stored in my database formatted as html, and users can
For the project that I'm currently on, I have to deliver specially formatted strings
I have date objects formatted like 2011/06/13 17:52:20 and being returned as strings. How
I have a problem for the managemente of decimal number in java (JDK 1.4).
I have a program that does text processing on a html formatted document based
I have a C# TCP chat program. Currently, I have formatted the messages sent

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.