|
Try this:
foo bar = new foo(1, new string[] {"1", "2", "3", "4"});
|
|
|
|
|
Much appreciated Robert, thanks so much!
|
|
|
|
|
hi all.
I just need to ask one question !
how can split the incoming string into string array by finite small string i know that split method for normal string can split the string into string array but with specific character not exceed one character like the following
--------------------------------------
<br />
using System;<br />
namespace snouto<br />
{<br />
class stringargs<br />
{<br />
static void Main(string[] args)<br />
{<br />
string string1 = "hi#thatisme#yeah";<br />
char[] splitters = {'#'};<br />
string[] separated = string1.split(splitters);<br />
}<br />
In the above code i split my string into string array using # character format but if i want to split my string by using another string like "snouto" in tha above string
<br />
string string1 = "hisnoutoThatismesnoutoYeah";<br />
how can i split the above string using snouto which repeated inside the string
Please help
Miss With The Best And Die Like The Rest
|
|
|
|
|
AFAIK, there is no predefined method for what you want to do. You have to explicitly loop through the characters in the string and split them. Off the top of my head,
string[] Split(string text, string separator)
{
ArrayList splitStrings = new ArrayList();
int index = -1;
int prevIndex = index;
while ((index = text.IndexOf(separator, prevIndex)) != -1)
{
splitStrings.Add(text.Substring(prevIndex, index-prevIndex));
prevIndex = index + separator.Length;
}
return (string[]) splitStrings.ToArray(typeof(string));
}
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
|
Instead you can rely on more popular regular expressions.
try this...
<br />
using System.Text.RegularExpressions;<br />
<br />
string original = "hisnoutoThatismesnoutoYeah";<br />
Regex reg = new Regex("snouto");
string[] splitStrings = reg.Split(original);<br />
Using Regular Expressions is comparatively faster that any other operations directly on strings
Hope this helps!!!
Regards,
Sidhu
IF YOU DON'T HAVE ANYTHING TO SAY, WELCOME TO THE CLUB
Dotnet @ Work Where Dotnet works...
My Blog
|
|
|
|
|
Hello:
I am trying to develop a flowchart generator.
It seems to me that i have to develop first a parser for the language being diagrammed.
Do you know of any starting point to do this? since on these days it seems that we are alway reinventing the wheel.
Best Regards
Roberto.
|
|
|
|
|
Hi am writing a chat server and I was stress testing my server and found some errors.
Say I have an arraylist.
ArrayList sockets = new ArrayList(listOfSockets);
Now I call Socket.Select to take out the sockets that don't have data on them.
Socket.Select(sockets, null, null, 100000000);
This is where the error happens, if I pass in a ArrayList that has 65 sockets in it.
It causes a IndexOutOfRangeException to happen. I have tried using other ways of doing it and it causes different errors but it always happens when it reaches 65 sockets.
I am dumbfounded please help.
------------------
I'm naked under my clothes...
|
|
|
|
|
|
Hi ...
I have created a ListBox on a Form. I would like to write to the ListBox from other classes using a wrapper method in the Form Class.
I have a public method in the Form1 Class called WriteStatusMessage(). This method will format the string and add the date and time and in the future could write to a file.
I would like to be able to call this method from other classes. In the sample code below I an able to create an instance of the Form1 Class and then call the WriteStatusMessage() method. Stepping through the code I actaully get into the method and to the point where I do the Add() on the ListBox.Item Object.
Any idea why the message will not display on the ListBox? As you can see I have tryed the Update() and Invalidate() method, both to repaint the ListBox?
Thanks,
Chris
<br />
<br />
using System;<br />
using System.Drawing;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Windows.Forms;<br />
using System.Data;<br />
<br />
namespace TestBlueRayon<br />
{<br />
<br />
public class Form1 : System.Windows.Forms.Form<br />
{<br />
<br />
<br />
private void menuItemVideo_Click(object sender, System.EventArgs e)<br />
{<br />
string strMessage;<br />
<br />
strMessage = "Create Video Object";<br />
WriteStatusMessage(strMessage);<br />
<br />
Video GreenVideo = new Video();<br />
<br />
GreenVideo.SetVideoContrast();<br />
}<br />
<br />
<br />
<br />
<br />
public void WriteStatusMessage(string strMessage)<br />
{<br />
string strDisplayMessage;<br />
<br />
DateTime dtCurrent = DateTime.Now;<br />
<br />
int nYear = dtCurrent.Year;<br />
int nMonth = dtCurrent.Month;<br />
int nDay = dtCurrent.Day;<br />
int nHour = dtCurrent.Hour;<br />
int nMinute = dtCurrent.Minute;<br />
int nSecond = dtCurrent.Second;<br />
int nMillisecond = dtCurrent.Millisecond;<br />
<br />
<br />
string strTemp;<br />
<br />
strDisplayMessage = String.Format("{0,0:D4}.{1,0:D2}.{2,0:D2} {3,0:D2}:{4,0:D2}:{5,0:D2}.{6,0:D3} {7}",<br />
nYear,<br />
nMonth,<br />
nDay,<br />
nHour,<br />
nMinute,<br />
nSecond,<br />
nMillisecond,<br />
strMessage);<br />
<br />
this.ListBoxStatus.BeginUpdate();<br />
this.ListBoxStatus.Items.Add(strDisplayMessage);<br />
this.ListBoxStatus.EndUpdate();<br />
<br />
this.ListBoxStatus.Update();<br />
<br />
}<br />
}<br />
}<br />
<br />
<br />
<br />
namespace TestBlueRayon<br />
{<br />
public class Video<br />
{<br />
public Video()<br />
{<br />
Form1 NewForm = new Form1();<br />
NewForm.WriteStatusMessage("Hello");<br />
}<br />
<br />
public int nColor;<br />
public int nHue;<br />
public string strComment;<br />
<br />
<br />
<br />
public void SetVideoContrast(int nIndex)<br />
{<br />
<br />
Form1 NewForm = new Form1();<br />
NewForm.WriteStatusMessage("Hello");<br />
<br />
nColor = 12;<br />
nHue = 34;<br />
strComment = "Contrast has been set";<br />
<br />
<br />
}<br />
<br />
}<br />
}<br />
<br />
Thanks,
Chris Macgowan
macgowan@pobox.com
|
|
|
|
|
Try taking off the BeginUpdate and EndUpdate calls sandwiching the Add method. I had the same problem once and taking off BeginUpdate and EndUpdate solved it, although I still don't know know why/how. Maybe it's a bug in the .NET framework.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
The problem I can see with your code is...
When you are trying to add elements to the listbox, you are creating a new instance of your form object. this will never point to the current form being displayed. So even if you call add(), it will add to the listbox on the form which is never displayed.
Instead, you have to get the reference to the existing form and then call add method.
Hope this helps!!!
Regards,
Sidhu
IF YOU DON'T HAVE ANYTHING TO SAY, WELCOME TO THE CLUB
Dotnet @ Work Where Dotnet works...
My Blog
|
|
|
|
|
Thanks IAMJUNK ...
The following is the solution to the ListBox Issue
Thanks also to Andy Tacker (CodeGuru)
Note that we added a reference to the form in the Video Class (m_ParentForm1). Then when we create the Video Object in the Form1 Object we will set the Video.m_ParentForm1 attribute to be <this> to set the reference back to the Form1 Object. Then when we want to use the Form1::WriteStatusMessage() method we can used the reference to Form1 from m_ParentForm1.
<br />
using System;<br />
using System.Drawing;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Windows.Forms;<br />
using System.Data;<br />
<br />
namespace TestBlueRayon<br />
{<br />
public class Form1 : System.Windows.Forms.Form<br />
{<br />
private System.Windows.Forms.MenuItem menuItemVideo;<br />
private System.Windows.Forms.ListBox ListBoxStatus;<br />
<br />
private System.ComponentModel.Container components = null;<br />
<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
WriteStatusMessage("TestBlueRayon Application Started.");<br />
WriteStatusMessage("Good to have you with us. ");<br />
<br />
}<br />
<br />
<br />
#region Windows Form Designer generated code<br />
private void InitializeComponent()<br />
{<br />
this.mainMenu1 = new System.Windows.Forms.MainMenu();<br />
this.ResumeLayout(false);<br />
}<br />
#endregion<br />
<br />
[STAThread]<br />
static void Main()<br />
{<br />
Application.Run(new Form1());<br />
}<br />
<br />
<br />
<br />
private void menuItemVideo_Click(object sender, System.EventArgs e)<br />
{<br />
string strMessage;<br />
<br />
strMessage = "Create Video Object";<br />
WriteStatusMessage(strMessage);<br />
<br />
Video GreenVideo = new Video();<br />
<br />
GreenVideo.m_ParentForm1 = this;<br />
<br />
GreenVideo.SetVideoContrast(0);<br />
}<br />
<br />
<br />
<br />
<br />
public void WriteStatusMessage(string strMessage)<br />
{<br />
string strDisplayMessage;<br />
<br />
DateTime dtCurrent = DateTime.Now;<br />
<br />
int nYear = dtCurrent.Year;<br />
int nMonth = dtCurrent.Month;<br />
int nDay = dtCurrent.Day;<br />
int nHour = dtCurrent.Hour;<br />
int nMinute = dtCurrent.Minute;<br />
int nSecond = dtCurrent.Second;<br />
int nMillisecond = dtCurrent.Millisecond;<br />
<br />
string strTemp;<br />
<br />
strDisplayMessage = String.Format("{0,0:D4}.{1,0:D2}.{2,0:D2} {3,0:D2}:{4,0:D2}:{5,0:D2}.{6,0:D3} {7}",<br />
nYear,<br />
nMonth,<br />
nDay,<br />
nHour,<br />
nMinute,<br />
nSecond,<br />
nMillisecond,<br />
strMessage);<br />
<br />
this.ListBoxStatus.Items.Add(strDisplayMessage);<br />
<br />
this.ListBoxStatus.Update();<br />
}<br />
}<br />
}<br />
<br />
<br />
<br />
<br />
<br />
using System;<br />
<br />
namespace TestBlueRayon<br />
{<br />
public class Video<br />
{<br />
<br />
public int nColor;<br />
public int nHue;<br />
public string strComment;<br />
public Form1 m_ParentForm1;<br />
<br />
public Video()<br />
{<br />
nColor = 0;<br />
nHue = 0;<br />
m_ParentForm1 = null;<br />
}<br />
<br />
public void SetVideoContrast(int nIndex)<br />
{<br />
nColor = 12;<br />
nHue = 34;<br />
strComment = "Contrast has been set";<br />
<br />
if (m_ParentForm1 != null)<br />
{<br />
m_ParentForm1.WriteStatusMessage("SetVideoContrast() called");<br />
}<br />
}<br />
}<br />
}<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
|
|
|
|
|
I want to write a program that will connect to my router and enter my username and pw and then send the command "enable" and input the pw to my router. Is there something out there that will someone what show me the light on how to do this? This will be done in C also.
thanks
I shall steal all the kittens.
|
|
|
|
|
sorry I should also say this will be done on a freebsd based platform also
I shall steal all the kittens.
|
|
|
|
|
I have a .NET server application on a machine with a static IP address who publishes a singleton object:
MyServerObject obj = new MyServerObject();
RemotingServices.Marshal(obj, "TheServerObjectIsHere.remote");
The client publishes his listener object to the server, and connects to the server:
MyClientObject obj = new MyClientObject();
RemotingServices.Marshal(obj, "TheClientObjectIsHere.remote");
MyServerObject serverObj = RemotingServices.Connect("tcp://someStaticIpAddress/TheServerObjectIsHere.remote");
serverObj.Hello();
However, the server needs to connect to the client object, who's published object is on some network outside the LAN. Since the client object is not on the server's LAN,
RemotingServices.Connect("tcp://someLanAddress/TheClientObjectIsHere.remote")
will not work, because the server isn't on the same LAN, therefore a client address like "tcp://10.10.10.1/Client.remote" means nothing to the server.
So my question is, how does .NET remoting work over a WAN or the internet? Or, if you specifically have knowledge in this area, how can I connect to a MarshalByRefObject when it is on a different network?
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Conversation With a Muslim
Judah Himango
|
|
|
|
|
the only way to do this is to grab the ip from the client on the outside.
also, I havent used the uri the same way you do. I see you have TheClientObjectIsHere.remote. Shouldnt that be TheClientObjectIsHere.rem?
Maybe it doesnt matter, just looking over my code and comparing it.
but to answer your question you would need to put the ip where someLanAddress is. Also, make sure you have access to their machine and there is no firewall to hamper it. You might need to provide credentials when you connect. At least I did on mine.
Hope this helps alittle.
Steve Welborn
Software Architect
|
|
|
|
|
I am having trouble passing a string that has special characters in it as an argument in a program. To be specific
Method Signature: methodName(string)
I need to pass the following string: QTextPrint("TestMessage")
methodName("QTextPrint("TestMessage")"); Doesn't work
methodName(""QTextPrint("TestMessage")""); Doesn't work
methodName("QTextPrint\(\"TestMessage\"\)); Doesn't work
methodName(@"QTextPrint\(\"TestMessage\"\)); Doesn't work
Even attempting the same type of action in a stringbuilder doesnt work.
Any ideas would be appreciated.
Regards
Bob Robey
|
|
|
|
|
try this...
methodName("QTextPrint(\"TestMessage\")");
I Hope this should work.
If not give this a shot
string param = "QTextPrint({0}TextMessage{1})";
param = string.Format(param, "\"", "\"");
Hope this helps
Regards,
Sidhu
IF YOU DON'T HAVE ANYTHING TO SAY, WELCOME TO THE CLUB
Dotnet @ Work Where Dotnet works...
My Blog
|
|
|
|
|
It's really quite simple:
In C/C++/C# a string is delimited by "
If you want to use " _inside_ a string you have to prefix this " (and only this one) with \
So #1 won't work because the first string ends before TestMessage,
#2 won't work because you start with an empty string (""),
#3 won't work because \( doesn't have to be escaped and
#4 won't work because the @ will mess up all your \'s.
Use methodName("QTextPrint(\"TestMessage\")");
This will work.
Regards,
mav
|
|
|
|
|
Thanks to both of you for your help.
I selected the option of building the string using formatting since there were many segments that need to be concatenated.
Problem Solved.
Best Regards
Bob Robey
|
|
|
|
|
I'm currently making a (not as simple as i previously thought) game, and i want to know how to make a savestate for it to save the game, if you dont know what a savestate is then its where you press a button to save your game, then when you load it, you are exactly where you where, doing whatever you where doing when you left, as though you had never left.
If this isnt possible, then i guess that i'll have to save all of my vars in a file and read them back in when you load the game, and you wont be in the middle of falling or whatever either
If you need to know about the game for whatever reason, here it is. And dont worry about any crazy stuff happening, its probably supposed to
http://www.freewebs.com/csharpprojects/GameRPG.zip
Enter brings up the start screen, space is the action button, talk to people, press A to attack them.(attack may run slow)
|
|
|
|
|
Have you heard of something called "Serialization". This saves the state of the objects. For more info check Code Project
Hope this helps
Regards,
Sidhu
IF YOU DON'T HAVE ANYTHING TO SAY, WELCOME TO THE CLUB
Dotnet @ Work Where Dotnet works...
My Blog
|
|
|
|
|
Hi everyone
I have a solution based on Secure Conversation using a Security Context
Token Service (which is just a web service) that gives out SCT's, a client
program gets the issued SCT. But the problem I have is can this client then
hold Secure Conversations with one or a number of other web services.
I have another web service the client signs and encrypts the message and
attempts to send the response to the web service but I get the following
error.
Error "System.Security.Cryptography.CryptographicException: WSE523: The
CipherData contents are invalid"
I have read that much between blogs and MSDN, im all read out lol, BUT! I
can call a web method within the SCTS web service from the client. From my
understanding from what I have read when the Security Context Token is cached
it is cached in the AppDomain for the SCTS web service now that explains why
I can call the Web Method from the client and it works but when I call the
second Web Service it cannot access the AppDomain cache to check the SCT.
THEREFORE through WS-SecureConversation does all your Web Methods which the
client will call and sign and encrypt messages have to reside in the SCTS Web
Service.
Or can the client call as many other Web Services that are required of
course that reside on the same Server (have seen the implementations for web
farms).
So please please put me out of my misery can a client have a
SecureConversation with more than one Web Service and if they can how?
Thanks in advance
|
|
|
|
|
I have made a SnippetDB application like CodeLib Access version that fish made it
http://myweb.hinet.net/home4/s630417/
My problem is i want to use multiple access databases and I don not know how to store my connections or how to use it or simple how to start
For only one db is easy and my app is working but i can not figure how to do it for more.
Creating a db programaticly is not hard so pls help me with code if possible thx...
(o)(o)
|
|
|
|
|