|
David Amyotte wrote: return Int32.Parse(data, NumberStyles.Integer);
Yes, it will produce an error because you are telling the compiler that the string is representation of number but in reality it is representation of HEX number so you should specify NumberStyles.HexNumber
|
|
|
|
|
You could convert the bytes directly using System.BitConverter.ToIntXX. Using a BinaryReader and a MemoryStream might be more convenient as you dont need to keep track of the array index.
|
|
|
|
|
thanks for your help so far.
What I'm doing so far is writing the data in the buffer into a Byte array then converting it to stringbuilder and the output so far is:
55 55 FF AA 91 30 43 30 30 30 30 36 33 38 37 36 45 42 35 45 34 38 34 39 34 FF
what I need to do is find an easy way to extract this data:
36 33 38 37 36 45 42 35 45 34 and convert it to decimal so I can do some calculations on the data. I'm new to .net so I figured this would be a good training exercise for me
Regards
|
|
|
|
|
It depends on the format of the data, you will need to look it up or work it out.
36 could be a byte
36 33 could be short
36 33 38 37 could be an int/float
36 33 38 37 36 45 42 35 could be a long/double
...
...
Example if 36 33 38 37 36 45 42 35 45 34 consits of 5 shorts:
byte[] data = {0x36, 0x33, 0x38, 0x37, 0x36, 0x45, 0x42, 0x35, 0x45, 0x34};
BinaryReader r = new BinaryReader(new MemoryStream(data));
for (int i = 0; i < 5; i++)
Console.WriteLine(r.ReadInt16());
|
|
|
|
|
In my old c++ days, I would use my old function below;
BOOL IsValidFilename(const char *szFilename)<br />
{<br />
<br />
if ( (!szFilename) || (!strlen(szFilename)) )<br />
return (FALSE);<br />
<br />
if ( (strchr(szFilename, '.')) || (strchr(szFilename, '\\')) ||<br />
(strchr(szFilename, '/')) || (strchr(szFilename, ':')) ||<br />
(strchr(szFilename, '<')) || (strchr(szFilename, '>')) ||<br />
(strchr(szFilename, '*')) || (strchr(szFilename, '?')) ||<br />
(strchr(szFilename, '|')) || (strchr(szFilename, '\"')) )<br />
return (FALSE);<br />
<br />
return (TRUE);<br />
}
I thought there might be a cleaner way to test a string before I used it for a file name.
Programmer
Glenn Earl Graham
Austin, TX
|
|
|
|
|
Maybe slightly cleaner. The
Path.GetInvalidFileNameChars should give you an array of invalid chars, which you can iterate and check
IndexOf in your candidate file name.
"Once in Africa I lost the corkscrew and we were forced to live off food and water for weeks." - Ernest Hemingway
My New Blog
|
|
|
|
|
Thanks here is the final code it works perfectly...
bool IsValidFilename(String ^fileName)
{
if ( String::IsNullOrEmpty( fileName ) == true )
return false;
array<Char>^ invalidFileChar = System::IO::Path::GetInvalidFileNameChars();
for each ( Char ^i in invalidFileChar )
{
if ( fileName->Contains(String::Format("{0}", i)) )
{
String ^tmp = String::Format(L" '{0}' is invalid in a file name.\n", i);
System::Windows::Forms::MessageBox::Show(gcnew String(tmp),gcnew String(L"Warning"),
MessageBoxButtons::OK);
return false;
}
}
return true;
}
Programmer
Glenn Earl Graham
Austin, TX
|
|
|
|
|
That doesn't look like C# to me.
|
|
|
|
|
String.IndexOfAny() seems appropriate here.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
I'd just try it and catch the exception if any.
Let the OS/framework determine validity; it knows best.
|
|
|
|
|
But if its speed you want, catching the exception may not be the best solution.
Phil
|
|
|
|
|
Absolutely, why check what the OS/framework will check anyway? That's wasteful.
The custom check may be faulty, causing a false valid or invalid. A false valid will likely result in an exception anyway, so you've wasted the time on the extra check, plus the time writing the faulty check.
I know I couldn't write a filename validity checking routine as fast and accurate as the built-in one.
You don't know to what OSs the framework may be ported in future (I know, it's unlikely) and what their validity rules are.
I could certainly see adding some additional checking, like ensuring the name doesn't include a SPACE, or is 8.3 or something, but other than that you're just wasting your time.
This is a wheel best not reinvented.
|
|
|
|
|
Or a Regular Expression, matching any of the invalid characters.
|
|
|
|
|
I like that idea. A regex over a path size string should be blindingly fast as well.
"Once in Africa I lost the corkscrew and we were forced to live off food and water for weeks." - Ernest Hemingway
My New Blog
|
|
|
|
|
Hi All,
Is there any control/method/class/namespace available that i can use in my code in order to get windows XP like left menu.
Thank you!
"Mess with the Best, Die like the rest"
|
|
|
|
|
|
That was very helpful.
Thank You!
"Mess with the Best, Die like the rest"
|
|
|
|
|
Hi..
I have a web application(ASP.NET 2.0, C#), in which I am exporting a xml file.
The web page has a button called Export. When the user clicks the Export button, the File Download pops up, in which it has the Open,Save and Cancel Butons as in a normal file download pop-up. Being an xml file, the page also opens up,without the content behind the File download pop-up,
When the user clicks Cancel button, the file download pop up is gone, but the xml page(without the contents) is still open. This also happens when the user has successfully downloaded the xml file(Xml page is open)
Is it possible to close the xml page after the user clicks the cancel button and after the user saves the xml file? I am using Internet Explorer 6, Windows xp, SP1.
Please help.. Thanks
Thanks & Regards,
Venkat
|
|
|
|
|
i want to create a shape Control like that you got here. But his Control can t draw antialiased linies =/
How can i draw smooth linies ?
|
|
|
|
|
If I recall theres some settings on the Graphics object that can help you out. Anti-aliasing is more of a quality setting on the Graphics object, than specifically asking for the thing you are drawing to be smoothed.
|
|
|
|
|
Yea i use this already but it looks not really Antialiased =/
the edges of a pie, for example, looks fuzzy but not smoothed
I have a Custom Control wich inherits from the Control class and my paint code looks like this
protected override void OnPaint( PaintEventArgs e ) {
base.OnPaint( e );
if( ( this.Width <= 0 ) || ( this.Height <= 0 ) ) return;
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
GraphicsPath path = createGraphicPath( Shapes.Pie);
this.Region = new Region( path );
Pen pen = new Pen( new SolidBrush( borderColor_ ), borderWidth_ );
pen.DashStyle = borderStyle_;
e.Graphics.DrawPath( pen, path );
path.Dispose();
pen.Dispose();
}
|
|
|
|
|
Runtime error on accessing "role" from App.config file.
Any idea how to fix the problem?
Code:
string str = System.Configuration.ConfigurationManager.AppSettings["role"];
App.config:
<configuration>
<appsettings>
<add key="role" value="Easy">
<policyinjection>
<policies>
<add name="Policy">
Thanks
|
|
|
|
|
You will need to re-post since you forgot to check the "Ignore HTML tags in this message" check box. So we can't see your app.config or your error message.
Thanks,
Ben
|
|
|
|
|
Oops but i figured out the problem. Thanks anyway.
|
|
|
|
|
I need WinForms function which displays modal window with text given as parameter and returns value entered by user or null if esc pressed.
Where to find some source code for this ?
Andrus
|
|
|
|