Reputation: 1732
I've set MaskedTextBox's
Mask to: "Fl\air H\al ###.## , something here: ####.##"
When user inputs the value final text looks something like this:
Flair Hal 987.67 , something here: 1234.12
What will be the best way to extract 976.67 and 1234.12 from the MaskedTextBox's Text. I am looking for a List which will have all the values of the mask (976.67, 1234.12).
There can be any number of masks in the mask string and the mask can be any valid mask.
I am thinking of first removing '\' from the Mask and then in a for loop keep comparing the Mask with the Text and detect changes and add them to the List. But this doesnt sound good to me and i think there probably is a better way of doing it.
Upvotes: 1
Views: 6027
Reputation: 1732
Well i found out that there is no good way of doing it. As adrianbanks said i have to code myself to get this information.
I have written my own usercontrol which uses combination of labels and maskedtexboxes to get the input.
I use curly braces to indicate where i wan the masked textbox and the user control puts one masked textbox per pair of curly braces. "Flair Hal {###.##} , something here: {####.##}"
Then I can use the values collection which has the values for the masks.
Upvotes: 1
Reputation: 41
Use a regular expression. The following regex will work for your example, but you may have to tweak it depending on your actual mask:
\d*[.]\d{2}
Upvotes: 0
Reputation: 82944
There are four values of the mask in your example: 987, 67, 1234, 12. The fact that blocks separated by a . are treated as one is your own logic, so I think you will just have to write code to get the information yourself.
Have a look at the MaskedTextProvider property of the MaskedTextBox
, and its EditPositions property. The EditPositions
give you the positions within the Text
that the user could enter.
Upvotes: 1
Reputation: 43064
I would think that you would be to use TextMaskFormat to remove the literals and prompt characters from the .Text property. That way you'd only get the numbers (and spaces).
Upvotes: 0