|
In .NET 2.0 you can use the StringSplitOptions.RemoveEmptyEntries with the String.Split function. Otherwise when you load up your ArrayList just check if the strings contain only white space:
if (myString.Trim()="")
To convert back to a string can't you just iterate through the ArrayList and add each entry to a string, or even a StringBuilder?
-- modified at 16:53 Tuesday 9th May, 2006
|
|
|
|
|
Use foreach to iterate over the array and a stringbuilder and ToString ( if you're not using a string in your foreach ) to pass each object through the stringbuilder to build up your string.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
How can I insert a tab into the Text attribute of the Label of Winform?
For example
aaa: uuuuuuuu
bbbbb: yyyyyyyyyyyy
So in order to display
aaa : uuuuuuuu
bbbbb : yyyyyyyyyyyy
you must fill a tab character in. "aaa: uuuuuuuu" will be the text attribute of the Label.
Any help will be highly appreciated.
-- modified at 13:55 Tuesday 9th May, 2006
|
|
|
|
|
|
|
are you trying to write in from a visual-studio properties window?
because they will disable that option and just write \t, search the designer code for the label's text, and do it by hand, if there is a @ before the string, then erase it...
If the problam is continues, then something doesn't make sense, give a part of the code...
|
|
|
|
|
i have a binary tree class in SDI form program.
i want to print binary tree on that form using GDI commands.
can any one pls tell me how can do it.
pls give sample code to do it.
-- modified at 13:41 Tuesday 9th May, 2006
|
|
|
|
|
Create a BinaryTreeRenderer class.
public class BinaryTreeRenderer
{
public void Render(System.Drawing.Graphics graphics, BinaryTree theTree)
{
graphics.DrawLine(....);
}
}
"What classes are you using ? You shouldn't call stuff if you have no idea what it does" Christian Graus in the C# forum
led mike
|
|
|
|
|
I am porting a C# app from .Net 1.1 to 2.0. The app uses a native DLL. In 1.1, I used the following code successfully:
<br />
[DllImport(@"cbWaypoint.dll", EntryPoint="NEWJOB")]<br />
public static extern void NEWJOB();<br />
The DLL was located in the same folder as the assembly (bin/Debug).
However, when I try to do the same thing using 2.0, I get a DllNotFoundException:
Unable to load DLL 'cbWaypoint.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
Is anyone aware of changes to PInvoke in 2.0 that would cause this problem?
|
|
|
|
|
Does your native DLL have any dependencies that may be missing (i.e. must also be in the same folder or registered elsewhere on the machine)?
-Phil
|
|
|
|
|
I am needing to create an Options Window for my Applicaiton. Like in MS-Word when you go to Tools > Options > 'Options Window' you can specify settings for the app etc.
Can someone direct me to a tutorial or an article that talks about this stuff? Or tell me the techniques as to how to approach it?
Thanks in advance.
|
|
|
|
|
There is no pre-built "options window" in the .NET framework. You just create a new Form, add a bunch of controls which represent options, and provide some type of persistence mechanism to save/load the user's settings. You might want to use an xml config file to store the settings.
Josh
|
|
|
|
|
How about the Settings.settings file? Would that be a better choice?
|
|
|
|
|
I wish to include embedded code into a C# project so that I can debug the "real" thing and so that I can graph what is going on. Here is a little about the setup. We have A/D data coming in the serial port avery 3ms. I catch the data and can graph it today, nifty. Now, I want to include the actual firmware into the C# project and call that code when the samples arrive. This way, I run the real code, not a simulation, and can see what the firmware is doing. The acutal C code would be used, therefore, by two projects: C# and the embedded compiler. I am sure this can be done, but I'm just starting the process. I need to be able to call the C functions and also see the C variables (so that I can graph them if I wish).
To understand why this would be cool, consider doing some digital filtering on an incoming signal. You could view (on a graph) the raw data, and the filtered data. While we understand how this works in theory, there is nothing like being able to literally see the data live.
Please forgive this very general request, but I have to start somewhere. I'm heavy into embedded stuff, but the power of C# will be a wonderful tool to use. The graphing ability I all ready have (on just the raw data) has paid off in a big way. Thank you for any help you can provide.
Kenny
Kenny O'Dell
Prinicpal R&D Software Eng
Mettler-Toledo Inc.
Worthington, OH
|
|
|
|
|
To use your C code in a C# project, you will have to compile your C code to a dll and export those functions you want to call from your C# code. Also, any structures and data types will have to be redefined in your C# code. I would suggest reading up on P/Invoke since this is what you will have to do. An example is as follows:
/*In my C code*/
typedef struct MyStruct<br />
{<br />
int x;<br />
int y;<br />
char buf[ 80 ];<br />
}<br />
<br />
void Foo( MyStruct* pStruct );<br />
Compile this to, say, MyDll.dll.
Your C# code would do something like this:
[
LayoutKind(LayoutKind.Sequential)]<br />
public struct MyStruct<br />
{<br />
public int x;<br />
public int y;<br />
[MarshalAs(ByValTStr), SizeConst = 80]<br />
public string buf;<br />
}<br />
[DllImport("MyDll.dll")]<br />
public static extern void Foo( ref MyStruct );
I hope this helps get you started.
Deus caritas est
|
|
|
|
|
Thanks for the tip. I'll get started today. Of course, this leads to another question: you say to compile my C code as a DLL. How do I do that? You mean make a DLL project in studio? Suck the code in that way? Forgive me, but this is new territory for me. Hey, you want to talk about talking to an I2C device via discrete I/O pins, I'm your guy. Just getting going on the .NET world. I've successfully made quite a few apps with C#, but always with 100% managed code.
Look forward to your response.
Kenny O'Dell
Prinicpal R&D Software Eng
Mettler-Toledo Inc.
Worthington, OH
|
|
|
|
|
Yeah, make a DLL project in visual studio and export your functions that you want to call from your C# code. Make this an empty project. Then, add your .h and .c code to the project. Make sure to set the project property to compile as C code vs. compiling as C++ code. To export your functions you could put something like this in your header file.
<br />
__declspec(dllexport) void Func1( void );<br />
__declspec(dllexport) void Func2( void );<br />
I hope this helps get you started. There is tons of information on the web on creating dlls and exporting functions.
Deus caritas est
|
|
|
|
|
Please help me
I need to create an Array containing 100000 in the range from 0 99999 and no duplicates
Please show me the algorithms
Thanks so much
eric
|
|
|
|
|
there are only 100000 numbers in the range 0-99999, so of course there would be no duplicates.
Just loop from 0 to 99999 adding each number as you go!
Current blacklist
svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour
|
|
|
|
|
Random r=new Random();
for (int a=0;a<=99999;a++)
{
int b[a]=r.next(0,99999);
}
And for duplicates sorry i dont know.
nemanja
|
|
|
|
|
What I mean is for example
2, 7, 88, 33, ....
There are 100000 elements and 1 number created once , but they are random orders.
Not this: 2, 8 , 7 , 8, 7....
Sorry
Pls help
eric
|
|
|
|
|
Random r=new Random();
for(int k=0;k<=10000;k++)
{
int x=0;
int b[k]=r.next(x,10000)
x=x+1
}
Not a really good solution but it will work !?!;)
nemanja
|
|
|
|
|
Yeah,
That's true
Thanks anyway
eric
|
|
|
|
|
Like J4amieC suggested I would start by creating an array containing all your numbers sorted. Then just switch the numbers randomly in x iterations. Pick two random indices between 0 and 99999 and switch the two values in the array. If you make this long enough (probably 1 million times) than they should be ordered rather randomly.
int[] list = new int[100000];
for (int i = 0; i < list.Length; i++)
list[i] = i;
Random r = new Random();
for (int i = 0; i < 1000000; i++)
{
int i1 = r.Next(0, list.Length);
int i2 = r.Next(0, list.Length);
int temp = list[i1];
list[i1] = list[i2];
list[i2] = temp;
}
int counter = 0;
for (int i = 0; i < list.Length; i++)
if (i == list[i])
counter++;
|
|
|
|
|
Very smart solution
Thanks so much Robert
I'm fixing now
eric
|
|
|
|