|
|
you can use Substring method instead of Split method.
find the index of '=' character using IndexOf method and then pass this index + 1 as the parameter of Substring method.
|
|
|
|
|
Two things occur to me.
The first, to allow you to carry on using the same design that you have:
if (s == "" || s.StartsWith(" ") || s.StartsWith("/"))
{
continue;
}
fields.Add(s.Split(new char[] { '=' }[1])); <===== you might have to add a ToString(), or cast to a string
The second would be to use a Dictionary , rather than a List for fields . This would allow you to keep both parts; the setting name as the key and the setting value as the er.... value.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
If the value contains an equal sign, then also use the overload of Split that limits the number of strings returned.
|
|
|
|
|
If your cfg file is set out like:
Name=SK
FavWord=Delicious
So you only have one item per line, you should just be able to add the second element of the array:
foreach (string s in lines)
{
if (s == "" || s.StartsWith(" ") || s.StartsWith("/"))
{
continue;
}
string[] parts = s.Split(new char[] { '=' });
fields.Add(parts[1]);
}
Also, it might be worth your while to check out the Dictionary class, which may work out better for you. With a dictionary you can add an item like this:
myDict.Add("Name", "SK");
string m_name = myDict["Name"];
Handy stuff.
EDIT: Wow I need to post quicker. When I first hit 'Reply' this question had no answers!
My current favourite word is: Delicious!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
SK Genius wrote: EDIT: Wow I need to post quicker. When I first hit 'Reply' this question had no answers!
Ditto.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi all,
As per my requirement, while displaying date (i.e audit column) in datagrid is coming fine but same column while displaying in excel formate it is displaying as "2008-07-08" unable to get this (2008-07-08 20:24:14) formate i am using the following code
sbrHTML.Append(";.premium { mso-number-format:$\\#\\,\\#\\#0\\.00;} .ogDate {mso-ignore:padding;mso-generic-font-family:auto;mso-font-charset ;mso-number-format:yyyy-MM-dd;mso-background-source:auto;mso-pattern:auto;} ;");
then i am applying style for audit like the following
sbrHTML.Append(";" + (sqlDatareader.IsDBNull(columnIndex) ? "" : sqlDatareader["AUDIT_DATE"].ToString() + ";")); ogDate
For the above stmt i am able to get only this formate "2008-07-08" but i need to include time also.
Could any one help me in mso-number-formate: to get date formate like "2008-07-08 20:24:14"
thanks,
eswar.
|
|
|
|
|
In Excel you can format the cell with a Custom format of yyyy-mm-dd hh:mm:ss or as a Date with International (ISO) locale.
How you'd set that via C# I don't know.
|
|
|
|
|
You can use DateTime.ToString. Pass the format you want, for example yyyy-MM-dd hh:mm:ss. You'd have to hack through the documentation for more format strings information
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
Hi,
I have 2 forms and i'm trying to send string from Form1 to Form2,
I don't want to do it by using a constructor.
I want to do it with property.
Some one can help me?
Thanks in advance...
|
|
|
|
|
treuveni wrote: I want to do it with property.
So, create a public property in the Form2 and set it when you create and instance of Form2.
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Can you explain me how to do it?
|
|
|
|
|
|
Hell c# gurus , I am new to C# and im have a general question about c#
I have a datagrid , a text file full of urls and a string . Now the string is actuly the live data output of a program .
Ive already have written the code to import the entire text file into my data grid , What i would like to do is while importing the urls in the foreach loop check the value of s and see if it occurs anywhere in the live output string the value of the string t changes to pending .
Is there anyway to do this ?
const string fName = @"1.txt";
string[] lines = File.ReadAllLines(fName);
List<string> fields = new List<string>();
foreach (string s in lines)
{
int n = dataGridView1.Rows.Add();
dataGridView1.Rows[n].Cells[0].Value = s;
dataGridView1.Rows[n].Cells[1].Value = t;
}
|
|
|
|
|
Where does t come from ? If you create a class to contain s and t, then populate a list of them, you can make that the data source of your grid.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Hi im building a program in C# which downloads files , Ive wrote the code to generate the download graph and it works for values 30 - 100 but anyhing below 30 and the bar flips upside down .
I basically have 14 pixals to generate a bargraph of values 0 - 100 in . i know this is vague but im sure the problem is with GDI.FillRectangle(Graph, 1, 15 - Bar, 14, Bar - 1);
Can any ofr you c# gurus help me pinpoint the problem ()
private Graphics GDI;
private Bitmap DownloadGraphic;
private Icon icon;
private int value = 5;
public void DownloadGraph()
{
int Bar = (14 * value) / 100;
DownloadGraphic = new Bitmap(16, 16);
GDI = Graphics.FromImage(DownloadGraphic);
SolidBrush BackgroundBrush = new SolidBrush(Color.Transparent);
GDI.FillRectangle(BackgroundBrush, 0, 0, 16, 16);
Pen LeftBorder = new Pen(Color.White, 1);
GDI.DrawLine(LeftBorder, 15, 0, 15, 15);
GDI.DrawLine(LeftBorder, 15, 15, 0, 15);
Pen RightBorder = new Pen(Color.Gray, 1);
GDI.DrawLine(RightBorder, 0, 16, 0, 0);
GDI.DrawLine(RightBorder, 0, 0, 16, 0);
SolidBrush Graph = new SolidBrush(Color.DarkRed);
GDI.FillRectangle(Graph, 1, 15 - Bar, 14, Bar - 1);
Pen DownloadHilight = new Pen(Color.OrangeRed, 1);
GDI.DrawLine(DownloadHilight, 1, Bar, 14, Bar);
Font PercentFont = new System.Drawing.Font("Verdana", 7, FontStyle.Italic);
Brush Percentage = new SolidBrush(Color.White);
GDI.DrawString(value.ToString(), PercentFont, Percentage, 0, 1);
this.NotifyIcon.Icon = Icon.FromHandle(DownloadGraphic.GetHicon());
}
Thanks
|
|
|
|
|
Your code seems to work fine here - just your OrangeRed bar moves down as the rectagle gets bigger from the bottom - which looks a bit strange, but it is what your code asks.
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 im new to c# and im building a program to telnet my server. Im trying to prevent the situation below
HostName> A command that will take a long time
The next command HostName>
Where the application sends the next command before the server has completed the last one .
Here is my code
public void Run(string cmd)
{
System.Threading.Thread.Sleep(300);
string lastCharacter = Status.Substring(Status.Length - 2, 1);
if (lastCharacter == ">")
{
WriteLine(cmd + "\n");
}
else
{
Run(cmd);
}
}
I want to get rid of the System.Threading.Thread.Sleep(); functions because they are a major source of exceptions in the program . Is there anyway to solve this problem without System.Threading.Thread.Sleep() and withut sucking up all the CPU time ?
|
|
|
|
|
I have a thread reading the responses and it doesn't signal the sending code until it sees the expected response.
This is done in a telnet scripting class I wrote, but which is not yet ready for distribution.
|
|
|
|
|
Hi everybody, im trying to execute a .jar file in my c# program, i have try several times and get examples, but i can't do it.
I execute in the cmd, like this
java -Xms60m -Xmx256m -jar C:\\Programming\\Interface.jar";
and this open the program.
But, trying with the Process class:
Process process = new Process();
System.Diagnostics.ProcessStartInfo procInfo =
new System.Diagnostics.ProcessStartInfo("java -Xms60m -Xmx256m -jar C:\\Programming\\Interface.jar");
process = System.Diagnostics.Process.Start(procInfo);
and other instructions, i get an exception, the file can't be found.
Some one knows??
Thanks in advance.
|
|
|
|
|
If you would read the parameter's name, you would see that it's called fileName, therefore - there is no file name called "java -Xm......". Try
<br />
Process proc = Process.Start("java", "-Xms60m...."); <br />
Also, make you that java exec is in your env path, otherwise supply full path to it.
|
|
|
|
|
Thanks for the answer dude, but it's not working still, i dont get an exception, just a ms-dos window for a second.
Process proc = Process.Start("java",
"java -Xms60m -Xmx256m -jar C:\\Programming\\Interface.jar");
proc.EnableRaisingEvents = false;
proc.WaitForExit();
Have i write it correctly? I really don't understand why waitForExit is neither working..
|
|
|
|
|
FINALLY IS WORKING!!! Here is the code, thanks for ur time..
string path = "C:\\Programming";
Process process = new Process();
process.EnableRaisingEvents = false;
process.StartInfo.FileName = "java.exe";
process.StartInfo.Arguments = "-jar " + '"' + path+ "\\interface.jar";
process.Start();
|
|
|
|
|
Hi,
Use the following code to run .jar file from c#
private int ExecuteProcess(string cmd, string cmdParams, string workingDirectory, int timeout, out string stdOutput)
{
using (Process process = Process.Start(new ProcessStartInfo(cmd, cmdParams)))
{
process.StartInfo.WorkingDirectory = workingDirectory;
//process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.Start();
stdOutput = process.StandardOutput.ReadToEnd();
process.WaitForExit(timeout);
return process.ExitCode;
}
}
string stdOutput;
string parameters = "Prajwal";
int exitCode = ExecuteProcess(@"C:\Program Files\Java\jre1.6.0\bin\Java.exe", " -jar samplejarfilename.jar " + parameters
,path, 5000, out stdOutput );
|
|
|
|
|
Dear All,
I have 2 problems with the software I am devoloping.
1. Through data reader it gets data from As400 and inserts it into a local database. I have label that is supposed to notify regarding the status of the process. But its text does not change at all untill data is inserted into local access file. There are several commands to change the text between.
2. Do you have any idea how to get the completion rate of the inserting process?
Thanks in advance
|
|
|
|