|
So, if (str == null || str.Length == 0) then.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
I am not sure what you mean by "contains just \0". If you mean something like the C string terminator this is not really used and if you happen to get strings like this you will have to test for this case explicitly.
If you want to treat null references the same as empty strings you need a test like this:
if((str == null) || (str == ""))
Do not check the string length, by the way. Strings can contain characters such as writing direction markers that do not show. Hence, their length is > 0 but they are still empty!
cheers
erik
|
|
|
|
|
Yes, I did mean the C string terminator. If you write out a string to memory using MemoryStream and StreamWriter and then read it back in with a MemoryStream and StreamReader, you get that terminating \0 at the end of the string. However, (str == null), (str.Length == 0), and (str == "") all fail. The only solution I found was to use string.Trim to manually remove the \0.
|
|
|
|
|
Hi!
I have a problem thats been itching for days now and i really need help with this one.
I want to get the text that i write to begin from the bottom of the RichRTextBox, just like they having int the mIRC program.
im building a chat program and i need that thing too work.
hopes for an answer!
thanks
// trones
|
|
|
|
|
If you change the HideSelection property to false it will keep scrolling to the bottom. It will still start the text at the top, but will scroll down with it.
Maybe you could just pad it off the bat to bring it down?
Hope that helps..
-Sam
|
|
|
|
|
I want my C# program to be able to, at runtime, check a directory for small "drivers", display the drivers in a comboBox, and use the driver.
The drivers would just take in a string, parse it, and call a set number of functions like SetPos(x,y), SetHeading().....
It would be nice if they could be written in different languages, but that isn't necessary.
What would be the best way to go about this, could anyone point me to some info.
Thanks...
-Sam
|
|
|
|
|
The drivers could be DLL containing classes which implement a specific interface. With Reflection, you load them dinamically, and scan for the interface.
To simplify things (security), the drivers would be in a subdirectory of your application.
This would allow your users to create drivers in any .NET application.
If you want more end-user flexibility in choosing languages, go for COM and publish a typelibrary with an interface.
I see dumb people
|
|
|
|
|
Thanks for the reply, I will look into reflection...
|
|
|
|
|
Is it possible given two strings (class name and method name) to dynamically create an instance of the class and get a delegate pointing to the method?
For example (almostcode):
<br />
public delegate void ActionHandler(Message m);<br />
<br />
string className = <br />
"Exony.Runtime.StateServices.Test.States.Stopped";<br />
<br />
string actionName = "OnStart";<br />
<br />
Type t = Type.GetType(className);<br />
<br />
object instance = t.Assembly.CreateInstance(t.FullName);<br />
<br />
ActionHandler handler = ?CREATE_DELEGATE?(instance, actionName);<br />
<br />
fsm.Handlers += handler;<br />
<br />
Thanks in advance,
James.
|
|
|
|
|
Doh.... If you look hard enough there is nearly always something in the FCL to do the job...
ActionHandler handler = <br />
Delegate.CreateDelegate(typeof(ActionHandler), instance, actionName)
Thanks anyway...
James.
|
|
|
|
|
hi there
i have a problem using a text box
i have a text multiline box (accepts return = true) and TextBox1.Text=varText.
varText is a text with many lines (in fact is an XML source indented)
if i show the text with MessageBox.Show(TextBox1.Text) it looks fine but in the edit box instead of 'new line' i have '|'
what can i do?
any idea?
thanks in advance for your help
|
|
|
|
|
i had the same problem but i solved it like this:
msgbox.text = "texttext\r\n";
and it worked for mem so i suggest u should try that!
// trones
|
|
|
|
|
thank you for your answer, trones
i solve the problem this way:
char cr=(char)13;
char lf=(char)10;
string strCR,strLF,strCRLF;
strCR=cr.ToString();
strLF=lf.ToString();
strCRLF=strCR+strLF;
art=art.Replace(strLF,strCRLF);
textBox1.Text=art;
|
|
|
|
|
How can I find out if the computer is connected with a TCP-Network?
I don't want to find out if TCP is installed successfull, but I want to find out if there is a working TCP conntection to a network without using any IP adresses (that means on every computer without knowing anything about the existing network), etc.
There must be a solution, but I can not see the right method (
Can you help me?
|
|
|
|
|
Hi!
It's me again! I guess you need the IP-Adress of the Computer to find out if the connection is working
|
|
|
|
|
I wanna provide a MC++ lib for C# user. One function is: bool ReadString(string str)
I must write it in MC++ for some former code ReadBuffer.
I write it like something below, but failed in get the StringBuilder or String's char buffer. The marshal must be something wrong, can't pass the compiler.
bool ReadString(String * &str)
{
void * pBuffer;
int num;
ReadBuffer(&pBuffer, num);
StringBuilder* sb = new StringBuilder(64*1024);
MultiByteToWideChar(0,0,pBuffer, num, [MarshalAs(UnmanagedType.LPWStr)]sb, 64*1024);
str = sb->ToString();
}
Can anything lend me a hand?
|
|
|
|
|
I think this would be better asked in the MC++ forum.
I don't know whether it's just the light but I swear the database server gives me dirty looks everytime I wander past.
-Chris Maunder
Microsoft has reinvented the wheel, this time they made it round.
-Peterchen on VS.NET
|
|
|
|
|
novachen wrote:
I wanna provide a MC++ lib for C# user. One function is: bool ReadString(string str)
Do you mind if I ask why you are writing a library in MC++ to read a string. This can easily be done in C#, especially if other parts of the project will be written in C#. Could you provide further info?
Nick Parker
Not everything that can be counted counts, and not everything that counts can be counted. - Albert Einstein
|
|
|
|
|
Nick Parker wrote:
Do you mind if I ask why you are writing a library in MC++ to read a string.
In fact, the function is provided for a gzip lib. My ReadString's function is extract the text from the gz file. And because the dotnet use the Unicode char, i have to transform single byte into unicode (double bytes form). So the win32 api is used. When use the API, the address of buffer must provided, so i need some marshal on the String or StringBuilder.
Did i say it clearly now ?
|
|
|
|
|
novachen wrote:
Did i say it clearly now
yep - I knew I had an article bookmarked for something like this. Check out Mixing Managed and Unmanaged code[^]. Hope this helps.
Nick Parker
Not everything that can be counted counts, and not everything that counts can be counted. - Albert Einstein
|
|
|
|
|
i had host a email web service on a win2000 server. one of the parameter of the web service method call is "string filename". this "filename" will passed into
System.Web.Mail.MailAttachment class constructor to send email.
now, i have another standalone application which run on win98 computer. my standalone application want to send a image file which located in win98 computer.
can i just call the web service ws.SendMail("yccheok@yahoo.com", "c:\live.jpg"); without first explicit transfer the image file to win2000 server?
thank you.
regards
yccheok
|
|
|
|
|
No, you can't do that. What you can do however is use the new Web Services Development Kit and read this article on DIME[^] to do what you want.
I don't know whether it's just the light but I swear the database server gives me dirty looks everytime I wander past.
-Chris Maunder
Microsoft has reinvented the wheel, this time they made it round.
-Peterchen on VS.NET
|
|
|
|
|
previously, i had an application that use a COM object to grap image from web cam. i try to enhance my application by using the Windows Media Encoder 9 Series SDK to do live video streaming.
i realize that whenever i stop my image capturing thread and run WM live video streaming thread, my application has no problem at all the access the web cam device. however, whenever i try to stop WM live video streaming thread, the COM object unable the use the web cam device. it seems that the camera device still hold by the WM thread. the WM thread goes like this......
-----------------------------------------------------------------------
public void StartWM()
{
if(WMThread != null)
{
if(WMThread.IsAlive)
{
StopWM();
}
}
if(cameraThread != null)
{
if(cameraThread.IsAlive)
{
StopCamera();
}
}
WMThread = new Thread(new ThreadStart(_StartWM));
WMThread.Priority = ThreadPriority.Lowest;
WMThread.Start();
}
public void StopCamera()
{
if(cameraThread != null)
{
cameraThread.Abort();
while(cameraThread.IsAlive);
cameraThread = null;
}
}
public void StopWM()
{
if(WMThread != null)
{
WMThread.Abort();
while(WMThread.IsAlive);
WMThread = null;
}
if(Encoder != null)
{
Encoder.Stop();
//HOW TO MAKE SURE ENCODER
//IS COMPLETELY RELEASE ITS //WEB CAM DEVIDE HANDLE
//BEFORE IT PROCEEDS TO
//NEXT //STATEMET???????
//while(Encoder.IsAlive); <-
//- of course this
//wont work
Encoder = null;
}
}
private void _StartWM()
{
try
{
// Create WMEncoderApp and WMEncoder objects.
if(Encoder == null)
{
Encoder = new WMEncoder();
}
//encoder initialize
//code goes here for live
//video
//broadcasting
//Start the encoding
//process.
Encoder.PrepareToEncode(true);
Encoder.SynchronizeOperation = false;
Encoder.Start();
}
catch(Exception ex){}
}
-----------------------------------------------------------------------
whenever i wish to start the camera thread, i must first make sure the wm thread first release its handle to web cam. hence, i used to call StartCamera.
public void StartCamera()
{
if(WMThread != null)
{
if(WMThread.IsAlive)
{
StopWM();
}
}
if(cameraThread != null)
{
if(cameraThread.IsAlive)
{
StopCamera();
}
}
cameraThread = new Thread(new ThreadStart(_StartCamera));
cameraThread.Priority = ThreadPriority.Lowest;
cameraThread.Start();
}
-----------------------------------------------------------------------
inside _StartCamera, i will construct a camera COM object and capture image using that COM object. however, the COM object unable the use the web cam device whenever it wants to grap image
i suspect that the web cam is still hold by encoder. how can i make sure web cam is released by encoder after i call Encoder.Stop()?
thank you.
regards
yccheok
|
|
|
|
|
i had build a light weighted http server and recently realize that there is some bugs inside.
in my constructor, i initialize the TcpListener and the thread for receiving incoming request as follow:
----------------------------------
myListener = new TcpListener(port);
myListener.Start();
//start the thread which calls the method 'StartListen'
myThread = new Thread(new ThreadStart(StartListen));
myThread.Start() ;
----------------------------------
in my StartListen
----------------------------------
while(isRunnable)
{
//Accept a new connection
Socket mySocket = myListener.AcceptSocket() ;
if(mySocket.Connected)
{
//make a byte array and receive data from the client
Byte[] bReceive = new Byte[1024] ;
int i = mySocket.Receive(bReceive,bReceive.Length,0); //BUGS??
// rest of the code goes here
----------------------------------
sometimes, when i use a web broswer making an HTTP/GET request, my web broswer takes 5 minutes to download the contents from the computer that run light weighted server(LWS) and still get no responde. it seems that it can establish a TCP/IP connection to the LWS but get no response from the LWS.
finally, i realize that LWS will halt at the line.
-----------------------------------
int i = mySocket.Receive(bReceive,bReceive.Length,0); //BUGS??
-----------------------------------
this happen "sometimes". where "sometimes" LWS works fine and "sometimes" LWS dont :P
can anyone point me out how can i solve this problem? thank you in advance.
regards
yccheok
|
|
|
|
|
hi, all
How to invoke DLL in C#?
thanks very much
|
|
|
|