|
The quick answer:
int s = Convert.ToInt32(Duration.Substring(1, 1));
Why?
Try changing your code to this:
String line = "==XXXT08746=05/01/09 15:13 112 4 IT 0:01'22 0 #2 ";
string Duration = line.Substring(64, 9).Replace("#", "[#]");
string a = Duration.Substring(1, 2);
string b = Duration.Substring(3, 2);
string c = Duration.Substring(6, 2);
int s = Convert.ToInt32(a);
int y = Convert.ToInt32(b);
int l = Convert.ToInt32(c);
int NDura = s + y + l;
You will discover that duration equals " 0:01'22 " and so the string you are trying to parse is "0:" - thats why you keep getting the error.
Also this line:
string Duration = line.Substring(64, 9).Replace("#", "[#]");
Is kind of wierd as the Replace has no effect - as I mentioned Duration == " 0:01'22 ". No "#" there...
|
|
|
|
|
Thank you
I 've got it even if I've made alot of mistake like u said
now is my code
string Duration = line.Replace("'", "[']");
string LineOO = line.Replace("#", "[#]");
string Date = line.Substring(12, 8);
if (line.Substring(11, 1) == "=")
{
string Time = line.Substring(21, 5);
string Linein = line.Substring(27, 10);
string Lineout = LineOO.Substring(38, 1);
if ((string.Compare(Lineout, "0") > 0 || string.Compare(Lineout, "0") == 0) && (string.Compare(Lineout, "9") < 0 || string.Compare(Lineout, "9") == 0))
{
string Number = line.Substring(40, 20);
string Status = line.Substring(61, 3);
string NDuration = Duration.Substring(64, 10);
string b = NDuration.Substring(3, 2);
string c = NDuration.Substring(6, 2);
int y = Convert.ToInt32(b);
int l = Convert.ToInt32(c);
int NDura = y + l;
string Cost = line.Substring(75, 3);
string Detail = line.Substring(79, 2);
string Network = line.Substring(82, 8);
and it work
Thx
|
|
|
|
|
There is still room for some improvement.
Instead of getting a one character string, you can get a character. You can change this:
if (line.Substring(11, 1) == "=")
to:
if (line[11] == '=')
You can use the >= operator instead of doing both > and == comparisons. You can change this:
if ((string.Compare(Lineout, "0") > 0 || string.Compare(Lineout, "0") == 0) && (string.Compare(Lineout, "9") < 0 || string.Compare(Lineout, "9") == 0))
to:
if (string.Compare(Lineout, "0") >= 0 && string.Compare(Lineout, "9") <= 0)
However, you can use a char instead of a one character string there too:
char Lineout = Line00[38];
if (Lineout >= '0' && Lineout <= '9')
or simply:
if (Char.IsDigit(Line00, 38))
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Wowwww
It's so short and simply but I've never knoww.
thx very much
Code is ok but I 've just want to know how to decrease time to do it coz I have 10,100 data and it took a long time.
|
|
|
|
|
I while back I wrote this method that you can use to replace Int32.Parse, and that is about ten times faster. That could help to speed up it a bit.
public static int ParseInt32(string text) {
long value = 0;
long sign = 1;
bool first = true;
foreach (char c in text) {
if (c >= '0' && c <= '9') {
value = value * 10 + c - '0';
} else if (c == '-' && first) {
sign = -1;
} else {
throw new FormatException();
}
first = false;
}
value *= sign;
if (value < int.MinValue || value > int.MaxValue) throw new OverflowException();
return (int)value;
}
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
i need to get customer information from a java web service my client app is a C# . instead of calling the web service several times i want to get customer object , to do this i use a customer xsd and generated two classes one for c# and other of java ,then i added those classes to relevant party, in the java web service i create a customer object and fill it with info and send to c#, but in C3 it say that the passed object can't be implicitly cast ,any idea to solve this .
|
|
|
|
|
Whenever you modify the java code you need to update the references(proxy classes) in C# and then compile it.
I don't understand your problem exactly but hope this helps you.
"Don't worry if it doesn't work right. If everything did, you'd be out of a job." (Mosher's Law of Software Engineering)
|
|
|
|
|
I have my form currently set up with a treeview and a listview. The treeview shows all the folders with check boxes and the listview shows the files within the selected folder on the treeview.
I am trying to create a backup program which can successfully backup selected files/folders and successfully restore these at a later time.
My question is if anyone can give me any ideas on how to approach this? I'm thinking I would use an output textfile showing which files/folders were backed up and their fullpath?
|
|
|
|
|
Hi,
How do i select the whole listViewItem line (all the subitems of an item) when trying to copy it in the clipboard?
I have a listView with 5 columns. When i try to select 1 row it only selects the first column value not the whole row..
any ideas?
Regards,
Alex
“Be the change you want to see in the world.”
|
|
|
|
|
Assuming this is a Windows Forms ListView.
I don't know if it will make any difference to a drag-drop operation, but ListView has a FullRowSelect property, which er... well it does what it says on the tin.
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.”
|
|
|
|
|
Set the FullRowSelect property to true.
for example,
listView1.FullRowSelect = true;
|
|
|
|
|
Check the properties.
listView1.FullRowSelect = true;
|
|
|
|
|
Hi people,
I have the a form in my application where the user can enter a data and time and then save it to a Mysql database. but I get a FormatExeption saying "Input string was not in a correct format" How can I convert from .net datatime datatype to Mysql database type ?
Heres my method for inserting a row that contains a datetime datatype
private void shiftInsertNewRow()
{
conn = new MySqlConnection
("datasource=localhost;username=admin;password=student;database=hospital");
conn.Open();
MySqlCommand command = new MySqlCommand
("insert into shifts(ShiftID, Starttime, Endtime, WardID, NurseID) select ?ShiftID, ?Starttime, ?Endtime, ?WardID, ?NurseID", conn);
command.Parameters.Add(new MySqlParameter("?ShiftID", MySqlDbType.Int32));
command.Parameters.Add(new MySqlParameter("?Starttime", MySqlDbType.Datetime));
command.Parameters.Add(new MySqlParameter("?Endtime", MySqlDbType.Datetime));
command.Parameters.Add(new MySqlParameter("?WardID", MySqlDbType.Int32));
command.Parameters.Add(new MySqlParameter("?NurseID", MySqlDbType.Int32));
command.Parameters[0].Value = shiftidTextBox.Text;
command.Parameters[1].Value = startTimeTextBox.Text;
command.Parameters[2].Value = endTimTextBox.Text;
command.Parameters[3].Value = wardShiftidTextBox.Text;
command.Parameters[4].Value = wardNameTextBox.Text;
command.ExecuteNonQuery();
conn.Close();
}
any help would be greatly appreciated
|
|
|
|
|
I would imaging it would work the same was as SQL Server. Convert the text to a DateTime object, then pass the DateTime object as a parameter.
Man who stand on hill with mouth open wait long time for roast duck to drop in
|
|
|
|
|
well I tried to assign a DateTime object to Value but it didnt work either
command.Parameters[1].Value = DateTime.Now;
command.Parameters[2].Value = DateTime.Now;
|
|
|
|
|
student1988 wrote: well I tried to assign a DateTime object to Value but it didnt work either
Define "didn't work". Exactly how did it not work? Did it cause an exception? Did it fail to compile? Did it run but the result was wrong? What?
Man who stand on hill with mouth open wait long time for roast duck to drop in
|
|
|
|
|
it threw the same format exception again.
|
|
|
|
|
now define 'it'
exceptions hold a lot of information, including exact line numbers. Which statement throws what?
the quality and detail of your question reflects on the effectiveness of the help you are likely to get
|
|
|
|
|
During runtime when I execute shiftInsertNewRow() method I get a Format exception at this line:
command.ExecuteNonQuery() that says input string was not in a correct format.
|
|
|
|
|
I am not sure, haven't used command parameters like that yet, however I expect the "Values" you provide should come as a string representation that converts automatically to the type you specified, hence:
1. the DateTime parsing will succeed only when the string was formatted according to your default DateTime format, which is a user's preference (see regional settings).
2. an empty textbox will not convert to most simple types; example: int.Parse("") throws an exception!
3. there is an issue about null; when null is intended, it must be specified as DbNull.Value
|
|
|
|
|
i try make a litle chat that will be server/client
but i have a major issu , when everithing is working local it seem i'm not able pass my gateway if i not forward manualy the required port.
now i have tryed the upnp and i think the code work but my netbox refuse the upnp protocole >>
so i feel not using upnp since not everyone able use it or they will have to enable it + i heard of lot of security issue.
now i searched an other way to do it and found nothing on net.
but i see msn is enable forward port in my non upnp box?? or even other app like azureus bit torrent accept in/out conection (they not forward the port in my netbox though).
so my question is how those programme able to do that on a non upnp gateway???
how can i do the same thing all i need is to echange 2 ligne of chat realy that can't be that hard ><.
(no need talk about why i do a server/client for each user that not the point, the point is how to deal with port).
chunk of code apreciate^^
|
|
|
|
|
Maybe with holepunching, you might want to look that up.
You're right though, NAT is a major issue. And it doesn't look like it's going away soon (maybe with IPv6 - which isn't going to be actually here soon)
|
|
|
|
|
I won't wait on something that may come out solution already exist since some app are able corectly setting my gateway just they not well documented.
|
|
|
|
|
I don't really understand you, and I'm afraid I don't speak French..
What do you mean, exactly?
|
|
|
|
|
trying to be more clear.
My friend send me "hello" in chat on my IP 83.231...... port : 666
now i need forward this port so the message "hello" is redirected on my PC where the chat is instaled
so i need forward port :666 send incoming soket to 127.0.0.1
one way to do it is manualy through gateway administration .
second is Upnp.(wich wont work on half computer).
third is what i search how msn/azureus/etc... do it on a non-upnp gateway.
|
|
|
|