Archive for the ‘C++’ Category
Visual Studio C# Regular Expressions Examples
Numeric values:
public bool isNumeric(string str) {
Regex pattern = new Regex("[^0-9]");
return !pattern.IsMatch(str);
}
Alfa values:
private bool IsAlpha(string str) {
Regex pattern = new Regex("[^a-zA-Z]");
return !pattern.IsMatch(str);
}
Alfa numeric values:
private bool isAlfaNumeric(string str) {
Regex pattern = new Regex("[^a-zA-Z0-9]");
return !pattern.IsMatch(str);
}
C++ Press any key to continue
When I write some console application in Bloodshed Dev C++ or Visual Studio, I hate bringing up comand line and typing in the whole path to the program I’ve just written. I found two short ways of having “Press any key to continue…” before the console window disappears. One of them is a good one and the other is bad.
1. Good one
int main()
{
// do something
cout<<"Press Enter to continue...";
cin.get();
}
Well, this one really is “Press Enter to continue…”, which shouldn’t be a problem
2. Bad one
int main()
{
// do something
system.("PAUSE");
}
This one is very bad! If you want to know why, read this article:
C++ Delay Function
#include <ctime>
void delay(int n)
{
clock_t start_time, cur_time; start_time = clock(); while((clock() - start_time) < n * CLOCKS_PER_SEC)
{}
}
int main()
{
// do something
delay(5);
// delays 5 seconds
}
