locked
Ignore string data ($) when parsing user input

    Question

  • My users will input the price of an item in a text box named PriceText. I need to use the price to perform some calculations.

    Price = Double.Parse(PriceText.Text)
    However, it is natural to include the $ in the text box. What is the best way to handle this? Is there a way to automatically remove/ignore a dollar sign or format the text box with a mask (I am new to VB)?

    • Edited by burg1n Wednesday, May 07, 2014 5:17 AM
    Wednesday, May 07, 2014 5:05 AM

Answers

  • I found the answer elsewhere:

    Price = Decimal.Parse(PriceText.Text, System.Globalization.NumberStyles.Currency)

    • Marked as answer by burg1n Wednesday, May 07, 2014 5:22 AM
    Wednesday, May 07, 2014 5:22 AM

All replies

  • I found the answer elsewhere:

    Price = Decimal.Parse(PriceText.Text, System.Globalization.NumberStyles.Currency)

    • Marked as answer by burg1n Wednesday, May 07, 2014 5:22 AM
    Wednesday, May 07, 2014 5:22 AM
  • Thanks for sharing the solution. :)


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Thursday, May 08, 2014 2:06 AM
    Moderator