|
I'm fairly close to retirement.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
OriginalGriff wrote: Which means that we will have to deal with it as maintenance in future... You mean rewrite it to resemble something that is remotely acceptable
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
"refactoring"
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Which is what is called if the CEO don't disagree. You still have to fix it.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Hi there
i am using ASP.Core Razor pages and i want to get the number or count of visitors like 22 visitor has been visiting this webpage .
How is the idea of that !
i will be so glad for a help .
thanks
|
|
|
|
|
Each time one visits, increment a counter in your DB.
When you show the page, retrieve the current count, and show it ...
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hi man
that is my query in DB SqlCommand command = new SqlCommand("select *from BranchSale_all WHERE bestellt_am > DATEADD (day, -3, GetDate())",connection);
using (SqlDataReader reader = command.ExecuteReader())
{
while(reader.Read())
{
BranchSales branch = new BranchSales();
branch.bestellt_am = Convert.ToDateTime(reader["bestellt_am"]);
branch.Anz_Versandbestätigt = Convert.ToInt16(reader["versandbestätigt"]);
elements.Add(branch);
}
return elements;
here should increment the counter ?!
|
|
|
|
|
Have you considered an UPDATE command?
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
no . i just wanted to display data with some infos on razor page with counter of visitors the webpage
|
|
|
|
|
Then just make up a number ... like the Julian day + 42.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
This doesn't just automagically happen. Without saving each visit to a database, there's no way you'll be able to display it.
Here's another tidbit - the only person that cares about usage metrics are admins. Every-day users don't give a rat's ass about anything that doesn't directly affect their access to the web site.
So, this feature is for a very restricted/small set of users. If you're sure you really want to do this, plan ahead, and finger out and implement the mechanisms involved BEFORE coding the rest of the web site. I would recommend that you use the session ID so that you don't artificially add "connections" from the same user's session.
I had to do something similar recently, but for a single database that supports about 20 applications.
Lastly, you should have posted this in the Web developemnt forum instead of this one. It's too late now, but remember for the next question you'll inevitably have, to post it in the most appropriate forum.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
I need to replace every 'a' char with 'b' char, every 'b' char with 'c' char and so on. I've tried to make this with if but code is very very long for every char. Exists a method how mo make this without if or switch or something like that?
This how i tried but i want a good method:
char[] chars = new char[inputString.Length];
for (int i = 0; i < inputString.Length; i++)
{
if (inputString[i] == 'a')
chars[i] = 'b';
else if (inputString[i] == 'b')
chars[i] = 'c';
else if (inputString[i] == 'c')
chars[i] = 'd';
else if (inputString[i] == 'd')
chars[i] = 'e';
else if (inputString[i] == 'e')
chars[i] = 'f';
else if (inputString[i] == 'f')
chars[i] = 'g';
else if (inputString[i] == 'g')
chars[i] = 'h';
else
{
chars[i] = inputString[i];
}
}
string outputString = new string(chars);
|
|
|
|
|
You can use the collating sequence of alphabetic and numeric characters to test whether they are in a certain range, and also to increment them to the next character, as follows:
string inputString = "The quick brown fox jumps over the lazy dog";
char[] chars = new char[inputString.Length];
for (int i = 0; i < inputString.Length; i++)
{
if (inputString[i] >= 'a' && inputString[i] < 'h')
chars[i] = (char)(inputString[i] + 1);
else
chars[i] = inputString[i];
}
Console.WriteLine(chars);
|
|
|
|
|
Richard's solution will work fine, but a better solution is to have two "translation arrays":
private const string transA = "abcdefghijklmnopqurstuvwxyz";
private const string transB = "bcdefghijklmnopqurstuvwxyza";
And then index them:
char[] chars = new char[inputString.Length];
for (int i = 0; i < inputString.Length; i++)
{
int index = transA.IndexOf(inputString[i]);
chars[i] = index >= 0 ? transB[index] : inputString[i];
}
string outputString = new string(chars);
That way, you aren't forced to use a "simple one character shift" on your Caesar Cipher - you can get more creative.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
OriginalGriff wrote: Richard's solution will work fine, but a better solution is to have two "translation arrays": WHAT?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
|
Using Linq:
string ss = string.Join("", inputString.Select(ch => (char)(ch + 1)));
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
but for numbers how to make? i need to replace 0 with 9 and so on
0 1 2 3 4 5 6 7 8 9
9 8 7 6 5 4 3 2 1 0
|
|
|
|
|
Now, you have changed the question.
int offset = '9' + '0';
string ciphered = string.Join("",
inputString.Select(ch =>
(char)
(
Char.IsDigit(ch) ? offset - ch : ch + 1
)
)
); Is this homework ?
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
modified 26-May-19 5:41am.
|
|
|
|
|
Yes, is homework, when i write the question i didn't know that for numbers is different than letters, then i tried and i realised that i don't know how to make this. If you are interested full task is that:
Make a crypt algorithm that replace all letters and number like that:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Z A B C D E F G H I J K L M N O P Q R S T U V W X Y
a b c d e f g h i j k l m n o p q r s t u v w x y z
b c d e f g h i j k l m n o p q r s t u v w x y z a
0 1 2 3 4 5 6 7 8 9
9 8 7 6 5 4 3 2 1 0
Example:
string: TEXTcsharp#2367
result: SDWSdtibsq#7632
Thank You for Help ! ![Big Grin | :-D](https://codeproject.freetls.fastly.net/script/Forums/Images/smiley_biggrin.gif)
|
|
|
|
|
What I am really interested in is how we can help you start studying, and experimenting, so that you get a firm basis for becoming the programmer you want to be.
In the real world, no one will write code for you, and, teachers, and job interviewers, will understand quickly when you try and explain what code does ... whether you wrote it, or not.
Let's see you complete your assignment by handling the differences in upper- and lower- case character handling.
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
You are right, but i don't have a material from school or something like that, this "homework" is a contest from another country. This is the code and it works, thank you for all
int offset = '9' + '0';
string test = string.Join("", normal.Select(ch => (ch >= 'a' && ch < 'z') ? (char)(ch + 1) : (ch > 'A' && ch <= 'Z') ? (char)(ch - 1) : (ch == 'z') ? (char)'a' : (ch == 'A') ? (char)'Z' : ((char)(Char.IsDigit(ch) ? offset - ch : ch + 1))));
|
|
|
|
|
Do you think your code is now "original" enough to submit to a contest as your own work ?
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
But i don't send the code, i make this contest only for understand some things in C#. I'm not able to participate for this contest because is not for my country
|
|
|
|
|
That's good to know, and I think posing "code challenges" to yourself is an excellent way to learn !
I have found my students seem to understand Linq more quickly if I explain 'Select as meaning "transform each element, and return a new IEnumerable collection" ... and, 'Where as meaning "select."
Your code:
int offset = '9' + '0';
string test = string.Join("", normal.Select(ch => (ch >= 'a' && ch < 'z') ? (char)(ch + 1) : (ch > 'A' && ch <= 'Z') ? (char)(ch - 1) : (ch == 'z') ? (char)'a' : (ch == 'A') ? (char)'Z' : ((char)(Char.IsDigit(ch) ? offset - ch : ch + 1)))); While this is fine as "proof of concept," I'd ask you to imagine a programming job interview where you submitted your code, or this:
public string Encode(string source)
{
StringBuilder sb = new StringBuilder();
int offset = '9' + '0';
foreach (char ch in source)
{
if (Char.IsDigit(ch))
{
sb.Append((char) (offset - ch));
continue;
}
if (Char.IsUpper(ch))
{
if (ch == 'Z')
{
sb.Append('Y');
}
else
{
sb.Append((char) (ch - 1));
}
continue;
}
if (ch == 'z')
{
sb.Append('a');
}
else
{
sb.Append((char) (ch + 1));
}
}
return sb.ToString();
} Which version do you think more likely to get you a job ? Which version do you think you could more easily change if the encoding requirements changed ? Which version do you think another programmer could more easily understand ?
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|