How can i format a Double to String in c# so as to have only two decimal digits?
If I use String.Format("{0:0.00}%", myDoubleValue) the number is rounded, and i want a simple truncate without rounding. Also, I want the conversion to String to be culture sensitive.
I just want to add 1 day to a DateTime. So I wrote:
DateTime date = new DateTime(2010, 4, 29, 10, 25, 00);
TimeSpan t = new TimeSpan(1, 0, 0, 0);
date.Add(t);
Console.WriteLine("A day after the day: " + date.ToString());
I tought the result would be: 2010 04 30- 10:25:00 but I'm still getting the initial date.
What's wrong?
Hi all:
I am sending info to target email via PHP native mail() method right now. Everything else works fine but the table part troubles me the most. See sample output :
Dear Michael Mao :
Thank you for purchasing flight tickets with us, here is your receipt :
Your tickets will be delivered by mail to the following address :
Street Address 1 : sdfsdafsadf sdf
Street Address 2 : N/A
City : Sydney State : nsw Postcode : 2
Country : Australia
Credit Card Number : *************1234
Your purchase details are recorded as :
<table><tr><th class="delete">del?</th><th class="from_city">from</th><th class="to_city">to</th><th class="quantity">qty</th><th class="price">unit price</th><th class="price">total price</th></tr><tr class="evenrow" id="Sydney-Lima"><td><input name="isDeleting" type="checkbox"></td><td>Sydney</td><td>Lima</td><td>1</td><td>1030.00</td><td>1030</td></tr><tr class="oddrow" id="Sydney-Perth"><td><input name="isDeleting" type="checkbox"></td><td>Sydney</td><td>Perth</td><td>3</td><td>340.00</td><td>1020</td></tr><tr class="totalprice"><td colspan="5">Grand Total Price</td><td id="grandtotal">2050</td></tr></table>
The source of table is directly taken from a webpage, exactly as the same. However, Gmail, Hotmail and most of other emails will ignore to render this as a table.
So I am wondering, without using Outlook or other email sending agent software, how could I craft a embedded table for the PHP mail() method to send?
Current code snippet corresponds to table generation :
$purchaseinfo = $_POST["purchaseinfo"];
//if html tags are not to be filtered in the body of email
$stringBuilder .= "<table>" .stripslashes($purchaseinfo) ."</table>";
//must send json response back to caller ajax request
if(mail($email, 'Your purchase information on www.hardlyworldtravel.com', $emailbody, $headers))
echo json_encode(array("feedback"=>"successful"));
else echo json_encode(array("feedback"=>"error"));
Any hints and suggestions are welcomed, thanks a lot in advance.
Hy... I'm new in XML Schema, XSL,... (I have basic understanding)
On web page: http://w3schools.com/xsl/xsl_editxml.asp
is shown example for open,edit,save xml file, but with asp.
Do anyone know how can i open/edit and save xml file using php for next example:
<?xml version="1.0" encoding="ISO-8859-1"?>
<tools>
<tool id="1">
<field id="prodName">
<value>HAMMER HG2606</value>
</field>
<field id="prodNo">
<value>32456240</value>
</field>
<field id="price">
<value>$30.00</value>
</field>
</tool>
<tool id="2">
<field id="prodName">
<value>Audi</value>
</field>
<field id="prodNo">
<value>88885</value>
</field>
<field id="price">
<value>$26.00</value>
</field>
</tool>
</tools>
and do i need <tool id="2"> or just <tool> is enough.
Thanks very much on replay, and i don't need another xsl like shown on w3s, just fine is refresh submitted php file after submit (will do something with ajax after).
I saw replay from Mr. Writman on questions/377632/add-update-and-edit-an-xml-file-with-php
but that is for now 2 complex for me...:) is there any simpler answer (solution). Thanks in advance!!!
Having just upgraded to a newer version of HtmlUnit (2.4), I've noticed certain tests are failing when comparing the output of asText. Looking into the differences, this is because dates (present on the page in the format 11/06/2010 00:00z) are being altered in the output to read 2010-06-11.
Has anybody else encountered this, and can anybody advise how to turn off this (seemingly undocumented) feature of asText, which seems to go completely against the advised documentation.
I have a variable which is <type 'datetime.timedelta'> and I would like to compare it against certain values.
Lets say d produces this datetime.timedelta value 0:00:01.782000
I would like to compare it like this:
#if d is greater than 1 minute
if d>1:00:
print "elapsed time is greater than 1 minute"
I have tried converting datetime.timedelta.strptime() but that does seem to work. Is there an easier way to compare this value?
I'm trying to display a datetime from my MySQL database as an iso 8601 formated string with PHP but it's coming out wrong.
17 Oct 2008 is coming out as: 1969-12-31T18:33:28-06:00 which is clearly not correct (the year should be 2008 not 1969)
This is the code I'm using:
<?= date("c", $post[3]) ?>
$post[3] is the datetime (CURRENT_TIMESTAMP) from my MySQL database.
Any ideas what's going wrong?
Hello i have this line...
"00:02.0 VGA compatible controller: InnoTek Systemberatung GmbH VirtualBox Graphics Adapter"
how can i get the first numbers until VGA with SED in Bash script?
Thanks!
How do I diff two files in MSBuild? I cannot find any specific task to do it.
If possible, is it also possible to exclude certain rows, or patterns in the files eg.
2009-12-09T10:03:07.6888125+02:00
I am about to develop a application using Sencha touch. The issue i am facing right now is Sencha code should read the following XML ( "data.xml" and display News, Articles...), any expert that can help here please ?
<ns2:categories>
<category>
<catId>96</catId>
<title>News</title>
</category>
<category>
<catId>97</catId>
<title>Articles</title>
</category>
</ns2:categories>
and when i click on News as an example should read that particular "recordId" element in "data_read.xml" and display "origUrl","title","data" .the data_read.xml looks like below..
<ns2:records>
<record>
<recordId>96</recordId>
<title>123 Lifted</title>
<author>|</author>
<published>2010-01-20T14:36:00.000-08:00</published>
<origUrl>
http://www.abc.com/</origUrl>
<numComments>0</numComments>
<data>
<![CDATA[<p>According to a report on sd asdas das asdasd asdasd hjjasd .</p>
<p> </p>
<p>This is a landmark vote, and a harbinger of change for this extremely traditional area that also has banned the use of metal r bolt.</p>
<p> </p>
<p>Check out: abc.com and xyz .com for more information.</p>
<p class="modifydate">Last Updated (Wednesday, 20 January 2010 22:36)</p>]]>
</data>
</record>
</ns2:records>
IS this possible in Sencha ? Thanks for your help in advance
I have a Qt widget which should only accept a hex string as input. It is very simple to restrict the input characters to [0-9A-Fa-f], but I would like to have it display with a delimiter between "bytes" so for example if the delimiter is a space, and the user types 0011223344 I would like the line edit to display 00 11 22 33 44 Now if the user presses the backspace key 3 times, then I want it to display 00 11 22 3.
I almost have what i want, so far there is only one subtle bug involving using the delete key to remove a delimiter. Does anyone have a better way to implement this validator? Here's my code so far:
class HexStringValidator : public QValidator {
public:
HexStringValidator(QObject * parent) : QValidator(parent) {}
public:
virtual void fixup(QString &input) const {
QString temp;
int index = 0;
// every 2 digits insert a space if they didn't explicitly type one
Q_FOREACH(QChar ch, input) {
if(std::isxdigit(ch.toAscii())) {
if(index != 0 && (index & 1) == 0) {
temp += ' ';
}
temp += ch.toUpper();
++index;
}
}
input = temp;
}
virtual State validate(QString &input, int &pos) const {
if(!input.isEmpty()) {
// TODO: can we detect if the char which was JUST deleted
// (if any was deleted) was a space? and special case this?
// as to not have the bug in this case?
const int char_pos = pos - input.left(pos).count(' ');
int chars = 0;
fixup(input);
pos = 0;
while(chars != char_pos) {
if(input[pos] != ' ') {
++chars;
}
++pos;
}
// favor the right side of a space
if(input[pos] == ' ') {
++pos;
}
}
return QValidator::Acceptable;
}
};
For now this code is functional enough, but I'd love to have it work 100% as expected. Obviously the ideal would be the just separate the display of the hex string from the actual characters stored in the QLineEdit's internal buffer but I have no idea where to start with that and I imagine is a non-trivial undertaking.
In essence, I would like to have a Validator which conforms to this regex: "[0-9A-Fa-f]( [0-9A-Fa-f])*" but I don't want the user to ever have to type a space as delimiter. Likewise, when editing what they types, the spaces should be managed implicitly.
Hi,
I'm using Django to serve up some XML. Part of the requirements is that my dates are formatted as follows: 1969-12-31T18:33:28-06:00
How can I output a DateField in Django in that format?
I have been trying several regular expressions
$str =~ s/^0+(.)/$1/;
converts 0000 to 0 and 0001 to 1
$str =~ s/^0+./$1/;
converts 0000 to empty string, 000100 to 00, 0001100 to 100.
what difference is the parentheses making?
What is the best way to get formatted Int32 numbers?
Let say I have this o function:
string o(int x);
This is the value that o need to return according to x
x = 0 => o = 00
x = 1 => o = 01
x = 5 => o = 05
x = 10 => o = 10
x = 31 => o = 31
x = 106 => o = 106
I'm writing an iphone apps that receive data from an udp socket i can dispay what i receive using NSDATA description but is in hex format and for example it look like this:
<4c61742c 34343039 3131302e 35302c4c 6f6e2c39 38343237 352e3934 2c482c32 37392e30 302c4b6e 6f74732c 302e3032 2c4e616d 652c504c 41594552 2c496e64 65782c30 2c4d756c 7469706c 61796572 4e756d62 65722c30 00
i know that thi is a prase of compite sens how i can convert it ?
I want to accept values in any of the following format:
-$5
-$5.00
$5
$5.00
Is it possible to do that using Masked Input Plugin?
If not, what plug-in am I looking for?
How do I indicate a character is optional?
The code I've got so far
$.mask.definitions['~']='[ +-]';
$(".currency").mask("~$9");
I am a newbie in Python. I want to substract interval time from my log file, but the problem is I cannot convert millisecond string of log file into datetime format. For example, I have 15:55:05.12345 and I want to remove 5.12345 seconds from this string, and shwow result of 15.55.00.00000 in Python. How can I do that? Currently, I am using python 2.5.
Thank you in advance.
I am trying to achieve the following - one client-side proxy instance (kept open) accessed by multiple threads using a reliable session. What I have managed so far is to have either A) a reliable session with a client-side proxy which is created and disposed per call or B) what I aim for, but without a reliable session.
When I enable reliable sessions on my binding however, the following behaviour is exhibited:
Client-side
Upon application startup everything appears to work fine until roughly 18 messages in to the WCF session. I firstly get the proxy.InnerChannel.Faulted event raised, then an exception is caught at the point where I am calling the method on the proxy. The exception is a System.TimeoutException, with message:
"The request channel timed out while waiting for a reply after
00:00:59.9062512. Increase the timeout value passed to the call to
Request or increase the SendTimeout value on the Binding. The time
allotted to this operation may have been a portion of a longer
timeout."
The inner exception has a similar message:
"The request operation did not complete within the allotted timeout of
00:01:00. The time allotted to this operation may have been a portion
of a longer timeout."
With the method at the top of the inner stack trace being:
System.ServiceModel.Channels.ReliableRequestSessionChannel.SyncRequest.WaitForReply(TimeSpan timeout)
I then call proxy.Close followed by proxy.Abort (catching and ignoring exceptions). If I utilize the default settings (i.e. have simply <reliableSession/>), then calling proxy. Close results in another System.Timeout exception (although this time the allotted timeout is 00:00:00), however if I override the defaults as specified above no exception is thrown.
Service-side
Utilizing WCF tracing I get a System.ServiceModel.CommunicationException, with message:
"The sequence has been terminated by the remote endpoint. The session
has stopped waiting for a particular reply. Because of this the
reliable session cannot continue. The reliable session was faulted."
And a stack trace ending at:
System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result)
When remotely attaching to the server I get the same message, which occurs when code execution steps over the return statement of my service in the service call which causes the error.
The puzzling thing to me is that the service is stable and runs with options A) or B) as decribed at the beginning of my post, and occurs after a varying number of messages (around 18). The former fact points to there being nothing wrong with the code (indeed I have checked that no exceptions are thrown), and the latter just serves to confuse me and is why I modified the settings on the reliable session binding.
I am quite stuck on this. Can anyone suggest why the reliable session would fault in such a way?
I updated a working Cygwin/Screen setup on Windows 2k3 Server to Cygwin v1.7.2 and Screen 4.00.03. After updating, backspace no longer works. I haven't made any changes to my system or configuration. The Cygwin update went fine, and I don't have any custom changes in /etc.
Any ideas?
I have a string which holds 0.5. I have to convert in to 0.50.
I have tried following ways but nothing works.Please help
hdnSliderValue.Value is 0.5,I want workFlow.QualityThresholdScore to be 0.50
workFlow.QualityThresholdScore = Convert.ToDecimal(String.format("{0:d}",hdnSliderValue.Value));
workFlow.QualityThresholdScore = Convert.ToDecimal(String.format("{0:0.00}",hdnSliderValue.Value));
IS there any built in function or will i have to do string handling to accomplish this.
I'm trying to work with this XML feed that uses namespaces and i'm not able to get past the colon in the tags. Here's how the XML feed looks like:
<r25:events pubdate="2010-05-19T13:58:08-04:00">
<r25:event xl:href="event.xml?event_id=328" id="BRJDMzI4" crc="00000022" status="est">
<r25:event_id>328</r25:event_id>
<r25:event_name>Testing 09/2005-08/2006</r25:event_name>
<r25:alien_uid/>
<r25:event_priority>0</r25:event_priority>
<r25:event_type_id xl:href="evtype.xml?type_id=105">105</r25:event_type_id>
<r25:event_type_name>CABINET</r25:event_type_name>
<r25:node_type>C</r25:node_type>
<r25:node_type_name>cabinet</r25:node_type_name>
<r25:state>1</r25:state>
<r25:state_name>Tentative</r25:state_name>
<r25:event_locator>2005-AAAAMQ</r25:event_locator>
<r25:event_title/>
<r25:favorite>F</r25:favorite>
<r25:organization_id/>
<r25:organization_name/>
<r25:parent_id/>
<r25:cabinet_id xl:href="event.xml?event_id=328">328</r25:cabinet_id>
<r25:cabinet_name>cabinet 09/2005-08/2006</r25:cabinet_name>
<r25:start_date>2005-09-01</r25:start_date>
<r25:end_date>2006-08-31</r25:end_date>
<r25:registration_url/>
<r25:last_mod_dt>2008-02-27T14:22:43-05:00</r25:last_mod_dt>
<r25:last_mod_user>abc00296004</r25:last_mod_user>
</r25:event>
</r25:events>
And here is what I'm using for code - I'll trying to throw these into a bunch of arrays where I can format the output however I want:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://somedomain.com/blah.xml");
curl_setopt ($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_USERPWD, "username:password");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
$xml = new SimpleXmlElement($output);
foreach ($xml->events->event as $entry){
$dc = $entry->children('http://www.collegenet.com/r25');
echo $entry->event_name . "<br />";
echo $entry->event_id . "<br /><br />";
}
I have been trying several regular expressions in the substitution operator:
$str =~ s/^0+(.)/$1/;
converts 0000 to 0 and 0001 to 1
$str =~ s/^0+./$1/;
converts 0000 to empty string, 000100 to 00, 0001100 to 100.
what difference is the parentheses making?
Hello everybody.
I need to show user amount presented in different currencies. e.q. :
Your balance: $ 100 000.00
€ 70 000.00
3 000 000,00 ???.
So I need to use number_to_currency three times with different locales(en, eu, ru). What is the right way to do it?
How can I plot (a 3D plot) a matrix in Gnuplot having such data structure. I cannot find a way to use the first row and column as a x and y ticks (or to ignore them)
,5,6,7,8
1,-6.20,-6.35,-6.59,-6.02
2,-6.39,-6.52,-6.31,-6.00
3,-6.36,-6.48,-6.15,-5.90
4,-5.79,-5.91,-5.87,-5.46
Is the splot 'data.csv' matrix the correct parameter to use ?