|
Sorry i am not able to use these ...
as i have three int values ..
int i,j,k;
now i have to sort them..
how can i do ... can you please give some code snippted..
Thank you for your help...
vikas da
|
|
|
|
|
If you're wanting to be able to use SortOrder then something like this.
private SortOrder sortOrder;
private int MyIntComparer(int value1, int value2)
{
switch (sortOrder)
{
case SortOrder.Ascending:
return value1.CompareTo(value2);
case SortOrder.Descending:
return -(value1.CompareTo(value2));
default:
return 1;
}
}
Then just call Sort(MyIntComparer) on whatever collection your ints are in. The example below adds them to a List<int>
int i = 2;
int j = 3;
int k = 1;
List<int> intList = new List<int>();
intList.Add(i);
intList.Add(j);
intList.Add(k);
sortOrder = SortOrder.Ascending;
intList.Sort(MyIntComparer);
foreach (int item in intList)
{
Console.WriteLine(item);
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
|
|
|
|
|
Thank you very much for your help its done...
vikas da
|
|
|
|
|
Hi,
I am building a desktop application for embedded product.While running the application the program skips the following line :
char char1 = Convert.ToChar(response.Substring(0,1));
byte byte1 = Convert.ToByte(char1);
where response is the answer from the hardware to MSCOMM port
When Convert.ToByte conversion is done on some particular this code is skipped i.e. i am not able to get the byte1 can anybody tell the answer.
Thanks,
kanwal
|
|
|
|
|
Probably, after the line "byte byte1...", you are not using byte1. Just put a line "Trace.Write(byte1)" after the second line. And try again to set breakpoint to it.
|
|
|
|
|
tauras81 wrote: char char1 = Convert.ToChar(response.Substring(0,1));
There is no conversion needed, as it's already a char:
char char1 = response[0];
tauras81 wrote: byte byte1 = Convert.ToByte(char1);
A character is a 16 bit value, which you are trying to convert to an 8 bit value. This conversion will fail unless the character has a character code below 256.
Why are you trying to convert a character to a byte?
tauras81 wrote: When Convert.ToByte conversion is done on some particular this code is skipped i.e. i am not able to get the byte1
Unless you have a conditional statement that prevents the code from being run, code isn't just skipped. What do you mean when you say that you can't "get the byte1"? A byte variable always contains a value, does the value differ from what you expect it to be?
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi All
My code is already exporting datafrom a datagrid to an excel spreadsheet.My grid has student numbers and the modules they are registered for. example:
StudentID ModuleCode
s20600752 WIC2345
s20569875 POP3456
s20587466 TYU8765
s20569875 UYT6788
Now I want to be able to select a ModuleCode from the grid and only export students that are registered for that particular module.
Is this possible? please help?
|
|
|
|
|
hi everybody,
I have a text like this:
<img align=left valign=top src=http:
and I have pattern like this:
pattern = (?<name>\b\w+\b)\s*=\s*("(?<value>[^"]*)"|'(?<value>[^']*)'| (?<value>[^"'<> \s]*) |(?<value>[^"'<> \s]+)\s*)+
I wnat to get "src" block.
foreach (Match submatch in Regex.Matches(pattern))
{
submatch.groups....
}
It returns allways 2 groups; In this case it returns:
submatch.groups[1] = align
submatch.groups[2] = border
But I need http://www.takvim.com.tr/2008/09/11/im/7BC7F044C2062649A63A5239b.jpg
By the way, I have no only that template text.
it can be:
<a href=gnb102.html>
or
<a href="gnb102.html">
or
href=gnb102.html
or
href="gnb102.html"
etc...
Any Ideas?
Thanx...
I want to fly but I don't have wings
|
|
|
|
|
Set the ExplicitCapture flag when creating the Regex.
|
|
|
|
|
it has "RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture"
interesting point is:
if the text has " or ' it's working correctly
ex 1:
<img src="http://www.takvim.com.tr/i/spacer_trans_1x1.gif" width="10" height="1">
ex 2:
<img src=http://www.takvim.com.tr/i/spacer_trans_1x1.gif width=10 height=1>
ex 1: is working
ex 2: doesn't work
I want to fly but I don't have wings
|
|
|
|
|
I think you grouping might be incorrect. Try do the isolated cases first, then combine them once they are working. Currently you have no idea if it is the regex that is incorrect or the way the grouping has been constructed (it may be that it only allows the define the grouping name once, in that case you need to wrap the grouping around all possible options).
|
|
|
|
|
I tried with "The Regex Coach" program. There is no problem with pattern, it's working for all cases.
It seperates to groups correctly.
I'm confused...
(?<name>\b\w+\b)\s*=\s*("(?<value>[^"]*)"|'(?<value>[^']*)'| (?<value>[^"'<> \s]*) |(?<value>[^"'<> \s]+)\s*)+
may be ?<name> and ?<value> are problem. I don't know...
I want to fly but I don't have wings
|
|
|
|
|
enginço wrote: I tried with "The Regex Coach" program. There is no problem with pattern, it's working for all cases.
Then you probably did something wrong when copying the regex expression to code.
|
|
|
|
|
thanx for your reply,
I found the problem
| (?<value>[^"'<> \s]*) |
is wrong
|(?<value>\w[^"'<> \s]*)|
is correct
But both is OK on The Regex Coach program, in C# it's behave different.
Infact I don't know how is working getting groupCollection.
Anyway, it's solved. Thanx
I want to fly but I don't have wings
modified on Thursday, September 11, 2008 7:48 AM
|
|
|
|
|
Hi all,
I want to send a byte array to a C++ server in C#. Basically I want to know about socket communication in C#. Can someone let me the way to do it, any simple example really appreciate.
Thanks in advance.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
You could use a Socket, or use a TcpClient, the latter is rather simple, and MSDN should have a small sample.
|
|
|
|
|
Ya, I use TcpClient as follows.
<br />
try<br />
{<br />
testClient = new TcpClient("192.168.2.75", 5001);<br />
}<br />
catch (SocketException ex)<br />
{<br />
MessageBox.Show(ex.Message, "Socket Error", MessageBoxButtons.OK, MessageBoxIcon.Error);<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show(ex.Message);<br />
}<br />
Now my question is how to send a message though the client. Can you give me a help to do it.
Thanks
I appreciate your help all the time...
CodingLover
|
|
|
|
|
Just call testClient.GetStream() and then you have a Stream to sent and receive on.
|
|
|
|
|
Ya, thanks a lot. I've done it well. Now I'm doing some modifications on it. I get you if I have any questions.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
There is a great tutorial on TCPClient & TCPServer on GeekPedia[^] in the form of a client - server chat app. I actually based the project im working on for work's Client Server architecture on it.
That version is a bit buggy but i think its worth a read.
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.passion != Programming)
|
|
|
|
|
Hi,
I have a magnetic Card reader (Soft & Wireless Timeit) it is connected to the com port of my PC .
I want to read the tag(data) from the card (simillar to Credit Card) using C#.
if any one having the code pls help me
thaks in advance
|
|
|
|
|
Try to use the sample of SerialPort Class from MSDN.
|
|
|
|
|
The manufacturer of the reader will almost certainly be able to supply you with an SDK. Check their website or ask via e-mail
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.passion != Programming)
|
|
|
|
|
string lookFor; // used to store the restaurant name we are looking for
BOOL bFound;
//Take the 1st element in the linked list
while ( ! ListEmpty(l) )
{
lookFor = l->elem->restaurant; // Storing r. name for the current list element...
bFound = FALSE;
tmp = q->front; // Get the first element in the queue
while( ( ! QueueEmpty(q) ) && ( ! bFound ) )
{
cout << tmp->item << tmp->cuisine << tmp->mode << endl;
if ( ! strcmp(tmp->restaurant, lookFor) )
{
bFound = TRUE; // found what we were looking for!
}
else
tmp = tmp->next; // still not found, search further in the queue
}
if ( bFound ) // It was found
{
//Do what you please with the info in *tmp*
//it is the coresponding to the current list item
}
|
|
|
|
|
You keep asking the same thing, and at least 2 of us have asked for further clarification a couple of threads down from your original posts. I suggest that you re-read these comments carefully, and rephrase your question to address the points people have raised.
|
|
|
|