-1

i was wondering how i could split a string like "L-0,12,0,12", so that i only get the seperate numbers. -0,12 and -0,12. Those are two different numbers that i need to extract from the string. Does anyone know how to fix this? i have tried split for string, but then its splits all ','.

I want to get 2 outputs of output1 = -0,12 and output2 = 0,12.

There is nothing behind the string, only the first letter and then the 2 numbers in decimal. Its a SVG format coordinate. the full svg string is: "M0,-0,12 L-0,12,-0,12 L-0,12,0,12 L0,12,0,12 L0,12,-0,12 L0,-0,12", but i already had filterd the string by spaces so the array only returns every sub string with a letter as start of the string.

The picture shows what the output is of the string array if i split them with onlt the spaces as a split char.

Output of string array Its in C#.

SOLUTION : It was the culture settings that did the job. In my country numbers are separated with commas and in the English / US culture mode it is being separated with a '.' before the decimal. I changed the culture settings of my code before the code started running and now i get the SVG string format that i wanted to get, so i can divide them with the commas.

Fyi:

// Change current culture
            CultureInfo culture;
            if (Thread.CurrentThread.CurrentCulture.Name == "nl-NL")
                culture = CultureInfo.CreateSpecificCulture("en-US");
            else
                culture = CultureInfo.CreateSpecificCulture("nl-NL");

            Thread.CurrentThread.CurrentCulture = culture;
            Thread.CurrentThread.CurrentUICulture = culture;

Regards,

Giorgio

// using the method 
                    String[] strlist = regionString.Split(separator, count,
                           StringSplitOptions.RemoveEmptyEntries);
Giorgio R
  • 11
  • 4
  • Which programming language and which locale …? – Armali Jan 31 '20 at 10:49
  • 1
    Its in C# and .NET. Sorry, forgot to tag those also. – Giorgio R Jan 31 '20 at 11:59
  • Are strings to analyze similar? I mean, do they have a letter in front and then two decimal numbers and nothing behind? – Marco Jan 31 '20 at 12:41
  • There is nothing behind them, only the first letter and then the 2 numbers in decimal. Its a SVG format coordinate. the full svg string is: "M0,-0,12 L-0,12,-0,12 L-0,12,0,12 L0,12,0,12 L0,12,-0,12 L0,-0,12" – Giorgio R Jan 31 '20 at 12:47
  • I don't know SVG files structure, so I can't go too far with my opinions; what I can think of is using a Regex. – Marco Jan 31 '20 at 12:50
  • 1
    Have you seen [Parsing SVG “path” elements with C# - are there libraries out there to do this?](https://stackoverflow.com/q/5115388/1115360) – Andrew Morton Jan 31 '20 at 12:51
  • @AndrewMorton Thank you, haven't seen that post yet. Going to try to get it worked with that example code. – Giorgio R Jan 31 '20 at 13:03
  • I see that the regex parsing the SVG format to the arguments and Command, but the difference is that in the example the SVG format has numbers with decimals that contains '.' as the decimal separator and the ',' as the separator for the coordinates. At my example it contains only commas. Is there a way to get that worked around? – Giorgio R Jan 31 '20 at 13:33
  • @IanKemp Kind off. It shows a version of SVG format that is being parsed, but not the version i get from the SVG path. So im still looking to get this sorted. – Giorgio R Jan 31 '20 at 13:44
  • @GiorgioR What you are essentially asking for is a fully working solution. The answers on the linked question should provide you with something to build on to get to that solution. – Ian Kemp Jan 31 '20 at 14:36

1 Answers1

0

I don't know what you are doing, but presumably if you want to parse SVG data you are also planning to do something else with it, like display SVGs or modify them. You'd probably be better off using a NuGet package than inventing your own implementation, especially if you find it challenging to pick out the numbers from this string.

There is definitely something more to it than just "picking out the numbers". And I think there's at least three different versions of SVG (all of which may or may not use the same coordinate format, or formats). If you want to program it yourself, kudos for that. You should start by finding the docs for the SVG formats, so you know exactly how these coordinate strings are formed.

Dojo
  • 59
  • 1
  • 7
  • I know how they are formed. I have read the w3 SVG documentation, but its only to split those coordinates properly. Its a command from a different program. I need those coordinates to use them in a different program, since that program doesnt support SVG but only direct coordinates. I will look up NuGet packages if i can find any which can parse these commands. – Giorgio R Jan 31 '20 at 13:43
  • 1
    Googling "svg parser nuget" found several immediately. In any case, if you know the format, you should be able to do it with a little trial and error. Because you just provide an example and no description of the rules, I don't understand how the string is delimited, and I am not about to go and read the SVG docs in order to solve your problem for you. :) – Dojo Feb 03 '20 at 06:50