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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:22:30+00:00 2026-05-30T16:22:30+00:00

Hi how do you extract multiple decimals with different number of decimal places from

  • 0

Hi how do you extract multiple decimals with different number of decimal places from a string?
I’m looking to find a generic way to extract 3 numbers out the following strings.

e.g

CC77X1722X12 => 77,1722,12
PC77.5X10102X12.5 => 77.5, 10102, 12.5
XP60.25X0.333X12 => 60.25, 0.333, 12

The three numbers are always separated by ‘X’, and the string always starts with 2 characters

Thanks!

  • 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-30T16:22:31+00:00Added an answer on May 30, 2026 at 4:22 pm

    Since you have such a specific pattern, you don’t even need to use regular expressions. Because the first two characters can be ignored and all the numbers are separated by ‘X’ characters, this C# code should do the trick (with appropriate error handling added, of course)

    public IEnumerable<decimal> ExtractNumbers(string s)
    {                                                  // For s = "CC77X1722X12"
        string[] nums = s.Substring(2).Split('X');     // nums = ["77", "1722", "12"];
        return nums.Select(num => decimal.Parse(num)); // returns [77, 1722, 12]
    }
    

    For production code, though, I would recommend decimal.TryParse over decimal.Parse. To use that method, you could write something like

    public IEnumerable<decimal> ExtractNumbers(string s)
    {
        string[] nums = s.Substring(2).Split('X');
        return nums
            .Select(num => {
                    decimal d;
                    if (decimal.Parse(num, out d))
                        return new {Number = d, Succeeded = true};
                    return new {Number = 0, Succeeded = false};
                })
            .Filter(result => result.Succeeded)
            .Select(result => result.Number);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Extract the number after #/ from my string: abcdefg#/123 .
I would like to use the wikipedia API to return the extract from multiple
I want to extract word after first 'from' in the following string- anti-CD24 from
I need to extract data from my MySQL database into multiple text files. I
I'm looking to generate a single HTML file from the content of multiple HTML
I want to extract patterns that appert multiple times in a string. For example,getting
I am trying to extract columns from multiple text files(3000 files). The sample of
Extract a particular column value from multiple files ls -ltr -rwxr-xr-x 4 dc staff
I'm working with python and am trying to extract numbers from a .txt file
My goal is to extract certain nodes from multiple XML files with multiple namespaces

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.