|
Hi,
When converting from or to strings (even calling ToString(), you should ALWAYS use the culture in which you intend the formatting for. A general rule of thumb is always use English (us or uk) for internal stuff such as application logs and exporting/importing internal data, this way even when your software or data is moved between computers with different languages it will work. Use the UI culture and number formatting in the UI layer for UI interaction.
Look at this horror:
10.000
An American or english computer will read this as 10$
and a french, german and others will read this as 10000$
Fun fun fun
I think your code should look something like this:
String sEarnings = txtEarnings.Text;
double earnings;
bool earningsParseOk = Double.TryParse(
sEarnings, System.Globalization.NumberStyles.Any,
System.Threading.Thread.CurrentThread.CurrentUICulture.NumberFormat,
out earnings);
if (earningsParseOk)
{
}
else
{
}
|
|
|
|
|
gtr1971 wrote: think of the most common, elementary way you'd handle this problem and that is likely my answer
Mine too -- a NumericUpDown.
|
|
|
|
|
I replied to someone else by a mistake, please see my coomment, code included
|
|
|
|
|
Hi all
I must define a Hash Rule to control execution of a software from running by a human on a specific station.
I don't have the source code of software and so ... .
What i am doing is that this software must only be exceuted by another software written by me.
So a user may copy the installed files (on another PC) to the specified station and execute it (so bad).
So a Hash Rule is maybe the best method.
What i want is exactly that how to programmatically creating and dropping a "hash rule".
I don't want to manulally set the hash rule.
Note:
In Windows XP pro:
Run -> gpedit.msc -> Computer Configuration/Windows Settings/Security Settings/Software Restriction Policies/Additional Rules/ Right Click on the right panel / New Hash Rule ...
thanks
|
|
|
|
|
Your design will not work. When an application is launched, it is launched AS the user that is double-clicking the icon. You cannot prevent users of your application from launching the one your app is supposed to launch. Well, there is one method, but it is so easily defeated and the management/maintenance cost so high, as to not be worth the effort.
|
|
|
|
|
Thanks for reply
Dave, you are right, but i know another way
I think you mean that if an application is prevented from being run by hash code way, it can not be run by another application (mine) as well.
If you mean this, then i have a tricky solution for that, i manipulate the application binary source "exe" file (only a bit toggle is sufficient) so that it works fine, store it in the resource of my application. I extract it only while needed and then will be removed.
I know this way is not perfect, but the users of my application are not professional.
So my only problem is the question in the title of thread.
|
|
|
|
|
Mehrdad Seyrafi wrote: If you mean this, then i have a tricky solution for that, i manipulate the application binary source "exe" file (only a bit toggle is sufficient) so that it works fine
There's no need for this at all.
Mehrdad Seyrafi wrote: store it in the resource of my application. I extract it only while needed and then will be removed.
And there is still nothing from preventing the user from just copying the .EXE to another location and running it from there. If the app also needs to be installed or needs come components to be registered, well... let's just say this is getting more ugly than it already is.
There is simply no good method for doing this.
|
|
|
|
|
Hi, I got a problem with my datagridview sorting. When I use AutoGenerateColumns=true. It can do sorting. But when I set AutoGenerateColumns = false, I can't do the sorting. What am I missing here. Thanks.
|
|
|
|
|
|
Isn't there any simple solution, because it is working before the AutoGenerateColumns
|
|
|
|
|
Hello.
I am creating a program, where i need to have the 29 letter in Textbox1 to be replaced by t
Also xxxxxxxxxxxxxxxxxxxxxxxxxxx(t)xxxxxxxxxxx
Also.. My users, shall paste a link, there is about 30-40 letters, and number 29 shall be changed to a t.
Is that possible?
Regards Ahlmo
|
|
|
|
|
yes.
|
|
|
|
|
Can you show me ?
Also a tutorials or an example.
|
|
|
|
|
what you ask for is elementary string manipulation, read up on the String class, and start using some of its methods. If you don't feel comfortable programming in C# (or programming in general), I suggest you start by buying and studying an introductory book.
|
|
|
|
|
I have many books about c#, but can you show me an example for it ?
|
|
|
|
|
ahlm wrote: I have many books
Having them is not enough, you should study them. I'm not in a spoon feeding mood right now.
|
|
|
|
|
But do u know some good book titles then? I really need to learn it
|
|
|
|
|
It depends on your background.
I suggest you visit a book store and choose one or two. Read more here[^]
Year ago I liked "Microsoft Visual C#.NET Step by Step" by Sharp and Jagger.
|
|
|
|
|
Luc's being a 'meanie'! (although he makes a very good point)
Everything you need to do this as Luc said is in the String class - MSDN link[^].
A quick way to find out how to do something is to type the question into a search engine. For example, "how to replace a letter in string C#" with google returns this[^]. These results show many different ways of doing exactly what you want.
I don't mean to be sarcastic or condescending, but basic use of a search engine is an absolute requirement which you should always use as your first point of reference before asking on any programming site as you can be 100% sure that it has been asked and answered before unless it's a particularly technical or obscure question.
Once you have some answers, typing the class.methodname and appending MSDN will give you links to Microsoft's own documentation so you can read up on the finer points of the implementation possibilities of the options available.
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Thanks.
So this should work?
string str = "codeproject.com/script/";
str = str.Replace("codeproject.com/script/", "codeproject.com/scripl/"); <----
Also i have changed a "l"
|
|
|
|
|
That will work but it's not very versatile - if you just need to replace the word 'script'with 'scripl' then you should just use that part
string str = "codeproject.com/script/";
str = str.Replace("script", "scripl"); This doesn't deal with your original problem though, replacing one character a specific position with another. You could hard code something to alter just the 29th to 't', but then it wouldn't be reusable. I would create a method like
public static string ReplaceCharacter(string original, int index, char newChar)
{
} There are several methods which you will have come across through the google link.
There is String.Replace , but that replaces all occurences of a character or string inside the string plus you can't specify a position.
You could build a new string using a StringBuilder using the Substring up to the required character, appending the character you want and then appending the Substring after it. This would work but is a bit messy.
The method I would prefer is to convert the string to a char[] , change the character at the correct index then create a new string from the array. This would look something like this:
public static string ReplaceCharacter(string original, int index, char newChar)
{
if (index < original.Length)
{
char[] chars = original.ToCharArray();
chars[index] = newChar;
return new string(chars);
}
else
return original;
}
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
I have a class that inherits System.ServiceProcess.ServiceBase and is overriding the OnStart (string[] args) method. Where do I call base.OnStart(args)? At the beginning of the method or at the end?
protected override void OnStart(string[] args)
{
base.OnStart(args);
}
Or:
protected override void OnStart(string[] args)
{
base.OnStart(args);
}
|
|
|
|
|
Normally OnXxx methods are used for raising events (and occaisionaly other logic that relates to an action but that should be documented). If your code in Do stuffrelies upon this event already being raised (or any other logic that might be in the base method being applied) then you should call it first. If it's important that your Do stuff is done before any events are raised etc then you should call it afterwards. If it doesn't matter then it doesn't matter!
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
DaveyM69 wrote: If it doesn't matter then it doesn't matter!
when you're right, you're right indeed!
|
|
|
|
|
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|