Search code examples
c#stringglobalizationcurrencynumber-formatting

Get Associated Pattern String from a CurrencyNegativePattern


On the msdn documentation of (CurrencyNegativePattern) I notice that each number represents a associated pattern string.

There's any way to get this associated pattern string passing the corresponding number?

e.g:

<someClass>.GetNegativeAssociatedPattern( 9 ) // returns "-$ n"
<someClass>.GetNegativeAssociatedPattern( 3 ) // returns "$n-"

Thanks.


Solution

  • Since the table seems to be fixed, you can simply define an array with the patterns in your code:

    string[] patternStrings = { "($n)", "-$n", "$-n", "$n-", "(n$)", 
                                "-n$", "n-$", "n$-", "-n $", "-$ n",
                                "n $-", "$ n-", "$ -n", "n- $", "($ n)",
                                "(n $)" };    
    
    int GetNegativeAssociatedPattern(int index)
    {
        return patternStrings[index];
    }