Skip to content

Parsing fails when mapped abbreviations contain numbers #264

@bplubell

Description

@bplubell

Setting up by mapping an abbreviation to an unit:
UnitSystem unitSystem = UnitSystem.GetCached("en-US"); unitSystem.MapUnitToAbbreviation(UnitsNet.Units.AccelerationUnit.MeterPerSecondSquared, "m2");

The then following works as expected, printing "MeterPerSecondSquared":
Console.WriteLine(unitSystem.Parse<UnitsNet.Units.AccelerationUnit>("m2").ToString());

But parsing from Acceleration , I expect "12 m/s²" but it throws exception

UnitsNetException: Error parsing string. The unit is not a recognized AccelerationUnit.

Console.WriteLine(Acceleration.Parse("12 m2").ToString());

It likely lies with the regular expression pattern in UnitParser.ParseUnit.

This is important for me because I am expecting to parse user-typed input. It is not reasonable for the user to enter the pretty input of m/s², but rather m/s^2 which has the same meaning.

I will fork and try to work it out.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions