I want the user to first type a code (e.g. fkuk3463kj) The array is limited to 20. The rest must be filled with fillers. Which filler the customer will use (e.g. #, t, z,7,_,0) is his own choice and he will asked to define it at the beginning right after the question for the code.
(hint: afterwards (or if possible directly) I have to decide (to complete the wish of customer) whether the filler has to be at the beginning or at the end. (for example: fkuk3463kj########## or ##########fkuk3463kj)
Now I don't know how to implement this. I know, that it's not that difficult, but I don't get it! All my tryings were not really succesful.
Could anybody help me? This would be perfect! And many thx in advance!
Console.WriteLine("Please type in your company number!");
string companyNr = Console.ReadLine();
string[] CNr = new string[companyNr.Length];
Console.WriteLine("Type a filler");
string filler= Convert.ToString(Console.ReadLine());
string[] fill = new string[filler.Length];
.
.
.
.
.
(please pardon my english...)
As far as I can see, you're working with string:
// Trim: let's trim off leading and trailing spaces: " abc " -> "abc"
string companyNr = Console.ReadLine().Trim();
which you want to Pad with some char up to the length length (20 in your case):
int length = 20;
string filler = Console.ReadLine().Trim();
// padding character: either provided by user or default one (#)
char pad = string.IsNullOrEmpty(filler) ? '#' : filler[0];
// shall we pad left: "abc" -> "##abc" or right: "abc" -> "abc##"
// I have to decide (to complete the wish of customer)
//TODO: whether the filler has to be at the beginning or at the end
bool leftPad = true;
string result = leftPad
? companyNr.PadLeft(length, pad)
: companyNr.PadRight(length, pad);
// in case you want a char array
char[] array = result.ToCharArray();
// in case you want a string array
string[] strArray = result.Select(c => c.ToString()).ToArray();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With