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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:16:45+00:00 2026-06-01T12:16:45+00:00

I have to parse a String to create a PathSegmentCollection . The string is

  • 0

I have to parse a String to create a PathSegmentCollection. The string is composed of numbers separated by comas and/or (any) whitespaces (like newline, tab, etc…), also the numbers can be written using scientific notation.

This is an example: "9.63074,9.63074 -5.55708e-006 0 ,0 1477.78"

And the points are: P1(9.63074, 9.63074), P2(-0,555708, 0), P3(0, 1477.78)

To extract numbers I use a regular expression:

Dim RgxDouble As New Regex("[+-]?\b[0-9]+(\.[0-9]+)?(e[+-]?[0-9]+)?\b")
Dim Matches As MatchCollection = RgxDouble.Matches(.Value)
Dim PSegmentColl As New PathSegmentCollection
Dim PFigure As New PathFigure

With Matches

  If .Count < 2 OrElse .Count Mod 2 <> 0 Then Exit Sub

  PFigure.StartPoint = New Point(.Item(0).Value, .Item(1).Value)

  For i As UInteger = 2 To .Count - 1 Step 2
    Dim x As Double = .Item(i).Value, y As Double = .Item(i + 1).Value
    PSegmentColl.Add(New LineSegment With {.Point = New Point(x, y)})
  Next

End With

It works, but I have to parse about a hundred thousand (or more) strings, and in this way is too slow. I want to find a more efficient solution whereas: most of the times the numbers are not written in scientific notation and, if you think that’s a better way, I have no problem to use an assembly written in C++/CLI that use C/C++ not managed code, or C# unsafe code.

  • 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-01T12:16:46+00:00Added an answer on June 1, 2026 at 12:16 pm

    Why are you trying to parse the path markup syntax yourself? It’s a complicated thing, and perhaps a subject to be changed (at least extended) in the future. WPF can do this for you: http://msdn.microsoft.com/en-us/library/system.windows.media.geometry.parse.aspx, so it’s better to let the framework work.


    Edit:
    If the parsing is your bottleneck, you can try to parse yourself. I would recommend trying the following and checking if it’s fast enough:

    char[] separators = new char[] { ' ', ',' }; // should be created only once
    var parts = pattern.Split(separators, StringSplitOptions.RemoveEmptyEntries);
    double firstInPair = 0.0;
    for (int i = 0; i < parts.Length; i++ )
    {
        double number = double.Parse(parts[i]);
        if (i % 2 == 0)
        {
            firstInPair = number;
            continue;
        }
        double secondInPair = number;
        // do whatever you want with the pair (firstInPair, secondInPair) ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this that I need to parse into a 2D
I'd like to be able to create a string as %%variable%% and have it
I have some sort of recursive function, but I need to parse a string,
I have a large string I need to parse, and I need to find
I have a string: [\n['-','some text what\rcontains\nnewlines'],\n\n trying to parse: Regex.Split(@[\n['-','some text what contains
I have a date string and I want to parse it to normal date
I have a web method that returns a String[][] and I'm trying to parse
Possible Duplicate: How to parse JSON in JavaScript I have this JSON string: [{title:
Aloha I have a method with (pseudo) signature: public static T Parse<T>(string datadictionary) where
I have the following XML Parsing code in my application: public static XElement Parse(string

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.