|
If the DatagridView is bound and the "another form" opens from the form having these grids, you can send the datasource of the grids through a parameterized constructor.
|
|
|
|
|
The DataViewGrid is bound to a DataTable also generatet dynamically. I will try it. Thank you so fare
Rune
|
|
|
|
|
Greetings,
I am facing a problem with C#
I have a set of files that I want to replace any number that has -9999.**** (like -9999.1234 or any number that can be after the dot .) to be -9999.0000.
I have written a code that will put find any number that starts with -9999. However, I don't know how to replace it to be -9999.0000 . (the problem is finding and replacing the numbers after the . to be 0000)
If anybody can help me, that will be highly appreciated.
Thanks in advance.
Regards,
|
|
|
|
|
If you simply want to round nnn.xxx down to nnn.0, then you need to use Math.Floor. If that doesn't work then look at Math.Ceiling - I'm not certain which way round it works with negative numbers
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
Thank you for your reply.
But what I am trying to say is that I have a text file that has many number that begins with (let say -9999.) and the numbers have four digits after (like 1234 [any four digital number]).
What I want to do is that to replace any number that is after the . (like in -9999.1234 [which will be 1234])to be -9999.0000 ( the four digital after the . to be 0000).
In short, search the file for -9999.**** to be replaced to -9999.0000
Note:
* means any number.
Regards,
|
|
|
|
|
Is this a CSV file?
I would say use File.ReadAllLines and then use Regular Expressions to find the decimal numbers. Then using the Matches collection you can replace digits.
You can also use String.Replace method alone to do this.
|
|
|
|
|
Thanks...
the problem I am facing is that how can I make the code to replace any number (not specify number) with a specify number.
for example,
I have these numbers in the file:
-9999.1234
-9999.2345
-4021.0101
-9999.0987
-9999.7654
-7892.4132
-9999.0393
and etc...
I want any number that has -9999. (like -9999.1234, -9999.2345 and etc...) to be replaced with -9999.0000
I want a code that can do that in C#.
Note:
I wrote a code to read from the file and put each line in a array of type string.
What I want is that a code to replace any number that has -9999. (like -9999.1234, -9999.2345 and etc...) with -9999.0000
Regards,
|
|
|
|
|
Quick and dirty way:
string sFile = System.IO.File.ReadAllText(@"c:\test.txt");
string sRegEx = @"(\.[0-9][0-9][0-9][0-9])";
foreach (Match oMatch in Regex.Matches(sFile, sRegEx)) {
sFile = sFile.Replace(oMatch.Value.ToString(), ".0000");
}
System.IO.File.WriteAllText(@"c:\test.txt", sFile);
I would suggest you to search for a better Regular expression since, here I have hardcoded the number of digits after decimal.
|
|
|
|
|
d@nish wrote: string sRegEx = @"(\.[0-9][0-9][0-9][0-9])";
you can write
string sRegEx = @"(\.[0-9]{4})";
himanshu
|
|
|
|
|
Or better:
string sFile = System.IO.File.ReadAllText(@"c:\test.txt");
Regex r = new Regex(@"(\.[0-9][0-9][0-9][0-9])");
sFile = r.Replace(sFile, ".0000");
System.IO.File.WriteAllText(@"c:\test.txt", sFile);
He still needs to find a better regex though!
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Hi,
Do you need to know the fractional part of the number or will a simple text replacement suffice?
i.e.
If string starts with "-9999." then
string = "-9999.0000"
Alan.
|
|
|
|
|
The following regex finds all numbers that conform to the pattern -9.9999, where the first part can have any number of digits (and can be a positive or negative integer), but the part after the period is constrained to 4 digits.
Regex regex = new Regex(
@"(((?<Start>-?)(?<Part>\d*))(\.\d{4}))",
RegexOptions.IgnoreCase
| RegexOptions.Multiline
| RegexOptions.IgnorePatternWhitespace
| RegexOptions.Compiled
); You can then do a replace on this using the pattern:
${Start}${Part}.0000 This version of the code prevents you from incorrectly grabbing items such as A.1234 or the like.
[Edit]Modified because I didn't have Encode HTML tags when pasting set, and the group tags were hidden
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
modified on Tuesday, July 7, 2009 6:44 AM
|
|
|
|
|
Pete O'Hanlon wrote: Regex regex = new Regex( @"(((?-?)(?\d*))(\.\d{4}))", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled );
"parsing "(((?-?)(?\d*))(\.\d{4}))" - Unrecognized grouping construct."
This is the exception while using your regex.
|
|
|
|
|
See the modification above. I didn't have "Encode HTML tags when pasting" set, so the group tags were hidden
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Pete O'Hanlon wrote: This version of the code prevents you from incorrectly grabbing items such as A.1234 or the like.
Um, no it doesn't - you need to replace the '*' with a '+' or it matches 0 digits.
Regex regex = new Regex( @"(((?<Start>-?)(?<Part>\d+))(\.\d{4}))",
RegexOptions.IgnoreCase |
RegexOptions.Multiline |
RegexOptions.IgnorePatternWhitespace |
RegexOptions.Compiled );
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
OriginalGriff wrote: Um, no it doesn't - you need to replace the '*' with a '+' or it matches 0 digits.
Good spot.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
when i waz doing some project.......it asks user password....in zat page u can also change ur password..........but i just want to increase z size of z form and add some buttons.....i already create z button @ run time but it is not visible.....and i cant locate z location of z button....hw could i solve it???
|
|
|
|
|
Obviously English isn't your first language, so just a few points to help you improve and to increase your chances of being understood.
waz = was
zat = that
u = you
ur = your (sometimes you're - short for 'you are')
z = the
@ = at
hw = how
Creating the button isn't enough. You need to add it to the form's Controls property.
Button button = new Button();
button.Text = "&Created in Code";
button.Size = new Size(100, 23);
button.Location = new Point(12, 12);
this.Controls.Add(button);
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
DaveyM69 wrote: waz = was
zat = that
u = you
ur = your (sometimes you're - short for 'you are')
z = the
@ = at
hw = how
Gud1 Dave.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
DaveyM69 wrote: Obviously English isn't your first language
apparently his member profile says he's from US
regards
|
|
|
|
|
PandemoniumPasha wrote: apparently his member profile says he's from US
That doesn't mean anything. America doesn't have an official language, English is merely the convention, it is perfectly possible that his first language could be a different language.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Thank you man for helping. About the English, I just wanted to express my question. I think it would be no problem. Bye
What about now. I think my English is good.
|
|
|
|
|
No problem.
Your English is much better here. Complete with capitalisation and punctuation too!
Don't be too lazy, badly written text is just hard to read which leads to problems in comprehension for the reader. When you're asking a question to which you need an acurate answer, that is not an ideal situation.
I can't think of any situation in life where the kind of English you used before would be preferable. It may look cool in 'txts 2 ur m8s', but amongst intelligent people, such as you will mostly find here, it just makes you look a dick (IMO)!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
How can i detect bluetooth device and transfer the data from Pocket PC in C#
|
|
|
|
|