Write special masked TextBox for WPF - wpf

I want to develop a custom user control in WPF which has some sort of mask. this functionality is very like the one provided in many online applications where u enter your credit card number and next time whenever u sign in to your account u see only last for digits of the card number (something like ***4587) but while I display data in this way I want to keep real value unchanged so inside binding I will access full data.

You could try something like this:
string originalNumber = textBoxOriginalNumber.Text;
int numberOfDigits = textBoxOriginalNumber.Text.Length;
string hidden = new String('*', numberOfDigits-4);
textBoxModifiedNumber.Text = hidden + originalNumber.Remove(0, numberOfDigits-4);
It's is not an elegant solution but will help you if anybody else give you a better solution. Basically, it takes the original credit card number, counts how many digits it has, removes the "n-4" first digits, then show the * symbol "n-4" times plus the four last digits. This will work no matter how many digits the original number has.
Additionally, I'm not sure if a mask (or the Regex suggested by the other user bellow) would work because (if I understood it well) it would replace the whole number, instead of show the last 4 digits.

OK here is the way I resolved that issue. after working with Card numbers I wanted to work with ID and SN numbers as well so what I did was just wrote little method which takes in string and returns masked value here it is in case someone needs this in feature.
public static string GetMaskedNumber(string unsecuredNumber, char maskChar)
{
return unsecuredNumber.Substring(unsecuredNumber.Length - 4)
.PadLeft(unsecuredNumber.Length - 6, ' ')
.PadLeft(unsecuredNumber.Length, maskChar);
}

You could use Regex.Replace with \d to indicate a digit
i.e.
var digits = new Regex(#"\d");
modifiedNumber = digits.Replace(originalNumber, "*");
Or if you want to update the whole set of numbers except for the last group
#"\d{4}-"

Related

Mask MUI input to be able to add one or two digit number

I am implementing an input, where the user should type number in the following format: 12/34/56. I have found that react-input-mask allows to do so. But my question now is how to make the mask either require the user to fully enter the number (to remove such cases 1_/3_/_5) or add zeros where the number wasn't entered.
Also, another thing I think of is to allow either one or two digits, but I haven't seen documentation on this in react-input-mask
I am willing to choose another mask library, if you know it can be done so.
I figured it out. There is a property called maskChar, if you set it to null, e.g <InputMask maskChar={null} mask="99/99/99" /> won't allow user to proceed to second number, without filling both digits.

How can I change an Element in an array, that contains a specific String?

As it is said in the title I could use some help regarding a problem I have with my App.
My App scans a Barcode and offers to safe this barcode in a table together with a second String that can be put in which describes the number of times you want to save this barcode.
The customInit of the cell displays this as the barcode on the left and a grey number on the right representing the count. All of this information is saved in an array of form list=["972537657, 12"; ...]
My last functionality I want to implement is to have a function check for a maybe already existing barcode in the table and if there is instead of inserting a new row with the same barcode and a different number I want my app to just add the number I put in , to the number of the already existing table element with this specific barcode.
My problem: The logic in this works fine ; if there is an already existing element execute this function if not just insert a new row with the input data.
But I Have no idea how to tell the app what to change and how I can access this element of the array.
Maybe someone has an idea (I can also add some of my code if someone would like to inspect my problem further)
First, find the index of the string your looking for, then remove it and insert it at the index.
let arr:Array = ["a","b","c"]
let indexOfA = arr.index(of: "a")
arr.remove(at: indexOfA)
arr.insert("YourString", at: indexOfA)
if you only care about the duplication, why don't use Set instead of Array.
var barcode:Set = ["972537657","972537651","972537653"]
let result = barcode.insert("972537651")
if result.inserted {
print("insert")
}else {
print("duplication")
}

putting 6 sets of numbers on the stage actionscript 3.0

I am trying to right a game where there is 2 rows of 6 sets of numbers that are randomly generated matching the 1st row numbers with the bottom row of numbers to see how many matches a turn you come back with.
i think the random generator problem is easy since the numbers are 1-35 use ceiling to get the numbers
my problem is i am very new to actionscript i do not know how to place on the stage the 2 rows of 6 random numbers i have several books i have scanned through as well as the web
nothing i try works.
can i get a little coding help here plese
Thank you so much for your time helping me
Chris
You can try something along these lines
var myArr:Array = new Array(1, 2, 3, 4, 5);
var tf:TextField = new TextField();
tf.text = myArr[0].toString();
tf.x = 200;
tf.y = 200;
addChild(tf);
See TextField class
and DisplayObject method .addChild()
You basically need to create multiple text fields and then add them to the movie.
Note that you need to embed the font glyphs you are going to use (0-9 I suppose)

character strings into arrays

This is/isn't homework...the printing of the list IS homework and that works great, the iscntrl() and Array stuff is 6 weeks from now stuff and giving me grief.
I want to create an array filled with the first 32 TLAs of the Ascii table so that when I print out a column / row chart of Decimal to Ascii code I can use iscntrl() to flag that it's an un-printable character. In its place I want to grab the next TLA in the array and print that instead of the non-graphical character.
I have the iscntrl() working fine. Just can't figure out the array thing. All the examples in the books I have and online want to demo grabbing input from the user and tossing it into the array. I want to give the array a list at the beginning in the code and pull from that.
Can someone either give me a good link for what I need or just tell me how to do the whole process?
I've got 32 three letter items and I need to populate the array and pull them out via a for loop.
Thanks.
You can declare an array like this, and pre-fill its values:
const char *ControlCharacterNames[] = {
"NUL",
"SOH",
"STX",
"ETX",
// etc
};
Then, you can access ControlCharacterNames as an array in your code.
http://publications.gbdirect.co.uk/c_book/chapter6/initialization.html, chapter "6.7.2. More initialization".
Long story short, you probably need something like
char *TLAs[] = { "TL1", "TL2", "TL3", "FYI", "WTH", /* ...and so on...*/ };
and then pull the one you need using it's index
printf(TLAs[3]); // print "FYI", the 4th TLA
Hope I understood your question right.

how do i Read keypad using C + AVR controller

I like to know how count the received values from. Im using an 4x4 keypad, and AVR studio as compiler
for example if I press button "1" I receive a "1" but if I press button "1" again it should be an "11" and not a "2",
int inputcounter;
if (button = 00x1)
{ // what should i do instead of
inputcounter++ to get "11" and not "2"
}
Thank you.
Based on the comment instead of inputcounter++, it sounds like you are trying to use a numeric value.
So you need to do:
inputcounter = (inputcounter * 10) + newvalue;
I'm assuming you are trying to read in a key sequence and compare it to a sequence stored in the microcontroller's memory (a secret code, for example). You have two easy ways of doing this.
Use an array. Each time a new input arrives, place it in the next array slot until you have read in your max number of input button presses.
Pack the keystrokes into a single number. Assuming your keypad returns 1 when 1 is pressed, 2 when 2 is pressed, etc, you can use an integer to track input. Initialize the variable to zero. Whenever an input comes in, multiply the variable's current value by 16 and add the incoming digit. Since you have a 4x4 keypad, you will have to treat incoming keystrokes as hexidecimal digits, not decimal digits (the other suggestions that multiply by 10 will limit you to only using 10 out of your 16 available buttons).
The number of keys you can track at a time will depend on how many long you declare your array (for option #1) or what size variable you use (for option #2).

Resources