|
xmen_xwk wrote: string[] mlines;
where is the "new" keyword?
try :
string [] mlines = new string [3];
Regards,
Tomi
|
|
|
|
|
thanks
but i dont know how much size of array will be there
for intance
if i wanna write
string [] mlines = new string [3];
mlines = string2.split('.')
it might be possible that splitted part more than 4,
then what i should write instead of 3
Becoming Programmer...
|
|
|
|
|
Hello,
In this case you don't have to instanciate the array, because the Split method returns an new instance of string[].
This will work:
string[] mlines;
mlines = string2.split('.');
All the best,
Martin
|
|
|
|
|
but that defining array in GD giving error as i said above
Becoming Programmer...
|
|
|
|
|
Hello,
It would help if youpost the error message.
But this works:
string test = "abc.def.ghi";
string[] testarray = test.Split('.');
All the best,
Martin
|
|
|
|
|
for error read my first post
and you are doing same as i said above
Becoming Programmer...
|
|
|
|
|
Hello,
xmen_xwk wrote: for error read my first post
and you are doing same as i said above
Sorry, but I'm loosing a little bit of patience write now, as your post seems a little rude to me!
Have you even tried what all the others and I suggested?
You where mixung up two different possibilities of how to use the string[].
1)creating an modifying a string array
string[] testarray = new string[3];
testarray[0] = "firststring";
testarray[1] = "secondstring";
testarray[2] = "thirdstring";
2)Getting a stringarray from the string.Split method.
my answere 10h ago[^]
So if you tried and still have problems, you should post all the involved code + errormessage.
We are trying to help you in our free time, so please respect that, and at least try to help us to help you!
All the best,
Martin
|
|
|
|
|
Martin# wrote: as your post seems a little rude to me!
sorry buddy but i wasnt in rude manner, you misundertood me or i wrote wrong sentences, and i never be rude for who are helping me and others...
i said "for error read my first post" because i thought that you forgot error or werent read that, anyway if you felt hurt then sorry
and about my problem :
string[] mlines;
mlines = string2.split('.');
this code works if i define
string[] mlines; in any event(click, load, etc) but its giving error if i define it in General declaration
the error is
"Object reference not set to an instance of an object."
Becoming Programmer...
|
|
|
|
|
Hello,
xmen_xwk wrote: sorry buddy but i wasnt in rude manner, you misundertood me or i wrote wrong sentences, and i never be rude for who are helping me and others...
My impression was, that you were not trying out what have been suggested.
But anyway, I have a wild guess write now.
I don't think that your problem is the string[] mlines, I think it's "string2" which is null.
Because you have not assigned a text at this time.
try:
if(string2!=null)
mlines = string2.split('.');
Hope it helps!
All the best,
Martin
|
|
|
|
|
Hello,
I am stuck up with one problem from last 4 days please help.
Problem: I have to write a code to simulate DEADLOCK among threads and the formula that is documented for detecting the deadlock is:
Formula: “Current Queue Length” = “Threads Count” AND “Process/% Processor Time” < 1
The Definition of “Current Queue Length” counter is
: This displays the total number of threads that are currently waiting to acquire a managed lock in the application.Iit displays the last observed value. This helps you identify inefficient synchronization mechanisms.
The count keeps on rising steadily.
But this Counter(Current Queue Length) always shows 0 value when I look at it's value through Perfmon utility
The code which I have written is as follows:
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace Threads
{
class Tester
{
static void Main( )
{
// make an instance of this class
Threads.ThreadingExamples.CPUSpinWithDeadlock p = new Threads.ThreadingExamples.CPUSpinWithDeadlock();
// run outside static Main
p.DoTest();
break;
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.IO;
namespace Threads.ThreadingExamples
{
class CPUSpinWithDeadlock
{
public bool locked = true;
public static Thread[] ThreadsArray = new Thread[10];
//Creating a var "Count" which should be in Critical Section to avoid concurrent access to it.
public static string Count = "You r in ";
public void DoTest()
{
Console.WriteLine("Press any key to continue");
Console.Read();
//Main Thread ------- Starts.
//Lock the var Count to avoid concurrent access by threads.
for (int counter = 0; counter < 10; counter++)
{
if (counter == 0)
{
ThreadsArray[counter] = new Thread(
new ThreadStart(ILoop));
}
else
{
ThreadsArray[counter] = new Thread(
new ThreadStart(Loop));
}
ThreadsArray[counter].Start();
}
}
public void ILoop()
{
Console.Write("First Thread ");
Lock(CPUSpinWithDeadlock.Count)
{
Count = "Main Thread";
while (true)
{
Console.WriteLine("Hello");
//Thread Sleep to reduce the CPU Utilization by current thread.
Thread.Sleep(1000);
}
}
}
public void Loop()
{
Console.Write("Calling lock ");
// To make remaining 9 threads wait for thread no 1 to release the lock acquired by it
//so that the remaining threads would be queued and the the counter value of "Current Queue Length"
// would go up.
CPUSpinWithDeadlock.ThreadsArray[0].Join();
Lock(CPUSpinWithDeadlock.Count)
{
CPUSpinWithDeadlock.Count = "Child Thread";
Monitor.Exit(CPUSpinWithDeadlock.Count);
}
}
}
}
Thanks & Regards,
Vikas M Pai
Software Engineer
|
|
|
|
|
Hai Everybody,
Have a nice day!
Can we use default parameters in C# if yes please tell me how or else give me an alternate way to achieve default parameter concept
Best Regards,
M. J. Jaya Chitra
|
|
|
|
|
No, you have to do this
void MyMethod(string s, bool b)
{
}
void MyMethod(string s)
{
MyMethod(s, true); // makes true the default
}
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
So we have to overload the methods in order to have default parameters is it right
Best Regards,
M. J. Jaya Chitra
|
|
|
|
|
M. J. Jaya Chitra wrote: So we have to overload the methods in order to have default parameters is it right
Yeah.
|
|
|
|
|
Hai guys, actually MarchallByReference is used to give permission to the remote application to access the particular class, but for what purpose the "UnMarshall" is used for?
|
|
|
|
|
Hi All,
I want to connect a crystal Report dynamically with database which changes accordingly but the table is same in all the database table name = “Stock “ Also I want to add condition
“SELECT * FROM Stock Where Date BETWEEN ‘xyz’ AND ‘abc’” Database used by me is ACCESS.
Any one help me. Thanks in advance.
Nikesh Kr. Yadav
CSS Infotech
Sec- 31
Gurgaon,
Haryana(India)
|
|
|
|
|
Looking at your message history, you post every question you have to at least three forums. Please don't do that, it's rude and annoying. Pick the right forum and ask there.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
try to search for an article in Code project..there shold be able to answer your question,because u need an example to do that.
Regards,
Tomi
|
|
|
|
|
i want to populate combo by file names which contain on specified folder on form load.still i couldn't find a way. can anyone help me to solve this.
|
|
|
|
|
System.IO.Directory.GetFiles
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
thank you very much.that's working. i was trying with System.IO.Path.GetFileName.
|
|
|
|
|
I am working on a program which loads rich text documents into a RichTextBox control. What I need is to grab the text of the current "line" (including any text that may have wrapped around to the following line) that I have my insertion point at in the text. I had thought that I might be able search backward as well as forward for the closest System.Environment.NewLine (capturing the index of each) and then do a Sting.Substring call using the indexes of each NewLine find, but for some reason, that is not working.
Are there any suggestions for how I could do this with greater success?
Thanks in advance.
-- modified at 23:38 Thursday 26th July, 2007
John 3:16: "For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life."
using Earth.Internet.WWW.CodeProject;
|
|
|
|
|
Two kinds of lines in RichTextBox:
1) The lines separated by newline characters i.e. richTextBox.Lines[]
2) Lines that wrap in the control
Get 2) using GetFirstCharIndexOfCurrentLine, GetLineFromCharIndex(richTextBox.SelectionStart) etc
A combination of these functions and properties should be what you need.
Good Luck.
|
|
|
|
|
Thanks for your suggestions. It looks like they have gotten me closer to what I am trying to achieve.
Take the below example:
Title
This is the third line of text.
This is the fourth line of text that
by example would wrap to the next line.
Currently, when having my insertion point in any of the first four lines, the result is as expected: I only get the line that I have my insertion point at. When I venture to the fifth line which is really for the purposes of this example a wrapped continuation of the fourth, it counts as the fifth line. How do I tell the difference between a line that is the result from wrapping text and one that is divided by a new line/return carriage?
Thanks in advance.
John 3:16: "For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life."
using Earth.Internet.WWW.CodeProject;
|
|
|
|
|
I'm sure there are several solutions but my first thought is as follows: e.g.
first
second
third
fourth that wraps fourth that wraps fourth that wraps fourth
that wraps
string[] lines = richTextBox.Lines;
i.e.
lines[0] returns "first",
lines[3] returns "fourth that wraps fourth that wraps fourth that wraps fourth that wraps".
1) Create a class LineClass with properties: int FirstCharacter, int LastCharacter, string Line.
2) Add an entry for each line to a List<LineClass>. Remember there is a return character between lines so that in my example:
first instance of LineClass FirstCharacter=0, LastCharacter=4, Line=first
second instance of LineClass FirstCharacter=6, LastCharacter=11, Line=second
3) Use GetFirstCharIndexOfCurrentLine to determine the cursor location.
4) Loop through List<LineClass> to get the line you need.
If the line is a result of wrapping, your answer in 3) will fall between FirstCharacter and LastCharacter for that entry. Otherwise it will equal FirstCharacter.
Good Luck.
|
|
|
|