|
You can use extract username using Substring method of string class.
Giorgi Dalakishvili
#region signature
my articles
#endregion
|
|
|
|
|
split your string on : and @ it will return u a string array...
and on 2nd index u will find the username
|
|
|
|
|
<[^:]+:(?<username>[^@]+)@(?<ip>[^:]+)(:(?<port>\d+))?>
This regular expression should work for most cases, it will include the username, ip and port (if given) in the named groups "username", "ip" and "port"
/edit: why does this board include smilies in code and pre tags? Annoying! Just imagine the smiliey being ": (" (without space)
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi ,
I want to enter date to a text box and automatically view it like this
01/02/2008
please..How to do..
Regards
|
|
|
|
|
DateTime theTime = ...;
myTextBox.Text = theTime.ToString ("d"); /ravi
|
|
|
|
|
Thanks a lot for help …
but I meant that
Some user need to enter date to a text box and the last should format that date and show the slash "/"
|
|
|
|
|
try a masked text box.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Maybe something like this in the text changed event?
if (textBox1.Text.Length == 8)
{
StringBuilder sb = new StringBuilder();
sb.Append(textBox1.Text.Substring(0, 2));
sb.Append("/");
sb.Append(textBox1.Text.Substring(2, 2));
sb.Append("/");
sb.Append(textBox1.Text.Substring(4, 4));
string displayString = sb.ToString();
DateTime tmpDateTime;
if (DateTime.TryParse(displayString, out tmpDateTime))
{
textBox1.Text = displayString;
}
else
{
MessageBox.Show("Invalid input.");
textBox1.SelectAll();
}
}
Dave
|
|
|
|
|
I was going to suggest using a masked text box or handling the lose focus event, but others have beat me to it and even provided a solution. One change I would make to Davey's suggestion is to use an ErrorProvider instead of a message box.
/ravi
|
|
|
|
|
Use a DateTimePicker instead.
And always use an ISO 8601 format: yyyy-MM-dd
|
|
|
|
|
PIEBALDconsult wrote: always use an ISO 8601 format: yyyy-MM-dd
You try getting UK users to enter data like that. I wish they would as it makes so much more sense - but they just complain as it's not intuitive for them! I always handle dates that way in code, but for the UI I have to use dd/MM/yyyy.
Dave
|
|
|
|
|
|
Thanks to all for your useful suggestions
|
|
|
|
|
I'm using Visual C#.Net coding
I have an array of bytes
public Byte[] byArrData;
I have to send 15 bytes command. In that 2 bytes( byArrData[4], byArrData[5]) is user input. It will be given as integer and it should be converted to hex and send higher byte first and then the lower byte.
For eg. UserId = 1000. In hex it is '03E8' so byArrData[4] = E8 and byArrData[5] = 03.
byArrData[0] = 0x40;
byArrData[1] = 0x12;
byArrData[2] = 0x00;
byArrData[3] = 0x05;
byArrData[4] = UserIdHigherByte;
byArrData[5] = UserIdLowerByte;
byArrData[6] = 0x00;
byArrData[7] = 0x00;
byArrData[8] = 0x00;
byArrData[9] = 0x00;
byArrData[10] = 0x00;
byArrData[11] = 0x00;
byArrData[12] = 0x70;
byArrData[13] = 0x05;
byArrData[14] = 0x0A;
How should I convert it and send in C#. Please help
|
|
|
|
|
(byte)n;
(byte)(n >> 8);
Write it as it is or you can put it in a loop.
Eslam Afifi
|
|
|
|
|
Can you explain it a bit more. What is n?
|
|
|
|
|
I didn't notice you have named the integer. n is the UserId
Eslam Afifi
|
|
|
|
|
I think this would work:
int num = 1000;
byte one = (byte)(0x00FF & num);
byte two = (byte) ((0xFF00 & num) >> 8);
So, you know 1000 is 03E8.
If you AND this with 0xFF00 then you get left with 0300 we then RIGH SHIFT it by 8 which leaves us with just 03
For the other half we AND the original number with 0x00FF which leaves us with 0x00E8
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
You don't have to AND with 1
Eslam Afifi
|
|
|
|
|
Exception System.OverflowException was thrown in debuggee:
Arithmetic operation resulted in an overflow.
Apparently I do.
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
int n = 1000;
System.Diagnostics.Debug.WriteLine((byte)n);
System.Diagnostics.Debug.WriteLine((n >> 8));
This compiles and runs fine.
Eslam Afifi
|
|
|
|
|
But this doesn't:
int n = 1000;
byte i = (byte)n;
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
No, it does.
int n = 1000;
byte i = (byte)n;
System.Diagnostics.Debug.WriteLine(i);
Eslam Afifi
|
|
|
|
|
Huh, what version of the framework are you using?
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
I targeted 2.0, 3.0 and 3.5 and it works with all of them. I don't know why you got that exception but ANDing with 1 just gives you another integer and it's just an extra operation.
Eslam Afifi
|
|
|
|