这是关于一般的最佳实践,不是针对单一语言,数据库或其他任何内容
我们都必须处理生成的输出,您可以报告"一个产品"或"两个产品".阅读不太好...有些人只是通过使用"一个产品"或"产品数量:(1)"来解决这个问题,其他人可能有其他解决方案.
在不同的口语中,事情可能会更加复杂!在法语中,当你的产品为零时,你会使用单数形式,而不是复数形式!(零产品)其他语言(中文,日文)甚至可能缺乏这些语法差异或者有两个以上不同的词来表示产品的数量.(例如,复数和更大的复数.)
但为了保持这一点,让我们专注于具有单数和复数单词的语言.
在设置新项目时,还必须生成报告,如何处理单数和复数单词?您是否在数据库中为单数和复数形式添加了两个名称字段?您是否在代码中添加了其他规则以将单词从单数转换为复数?你用其他技巧吗?
在处理需要跟踪单数和复数形式的项目时,您如何处理这个问题?
在尝试了设置EditText一个Int值,我已经试过转换的各种方式Int的值,该EditText会接受,但都失败:
processButton.setOnClickListener {
var intNo = inputText.text as Int
intNo *= 2
outputText.text = intNo as String // error = "required editable"
outputText.text = intNo.toString() // err: type mismatch
outputText.text = Int.toString(intNo) // type mismatch reqd editable
outputText.text = "What is going on?" // type mismatch reqd editable
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能设置EditText一个Int值?
如何通过Javascript脚本请求PHP页面并将数据传递给它?然后我如何让PHP脚本将数据传递回Javascript脚本?
client.js:
data = {tohex: 4919, sum: [1, 3, 5]};
// how would this script pass data to server.php and access the response?
Run Code Online (Sandbox Code Playgroud)
server.php:
$tohex = ... ; // How would this be set to data.tohex?
$sum = ...; // How would this be set to data.sum?
// How would this be sent to client.js?
array(base_convert($tohex, 16), array_sum($sum))
Run Code Online (Sandbox Code Playgroud) 如何在JavaScript函数中将JavaScript对象转换为JSON字符串?我需要将JSON字符串传递给JSP页面.
我试图在线计算向量的绝对偏差,也就是说,在接收向量中的每个项目时,不使用整个向量.绝对偏差是向量中每个项目与均值之间的绝对差值的总和:
我知道矢量的方差可以用这种方式计算.方差类似于绝对偏差,但每个差异是平方的:
方差的在线算法如下:
n = 0
mean = 0
M2 = 0
def calculate_online_variance(x):
n = n + 1
delta = x - mean
mean = mean + delta/n
M2 = M2 + delta*(x - mean) # This expression uses the new value of mean
variance_n = M2/n
return variance_n
Run Code Online (Sandbox Code Playgroud)
是否有这样的算法来计算绝对偏差?我自己不能制定一个递归定义,但更聪明的头可能会占上风!
我们都知道准备好的语句是抵御SQL注入攻击的最好方法之一.使用"IN"子句创建预准备语句的最佳方法是什么.是否有一种简单的方法可以使用未指定数量的值来执行此操作?以下面的查询为例.
SELECT ID,Column1,Column2 FROM MyTable WHERE ID IN (1,2,3)
Run Code Online (Sandbox Code Playgroud)
目前我正在使用一个循环覆盖我的可能值来构建一个字符串,如.
SELECT ID,Column1,Column2 FROM MyTable WHERE ID IN (@IDVAL_1,@IDVAL_2,@IDVAL_3)
Run Code Online (Sandbox Code Playgroud)
是否可以使用只传递数组作为查询参数的值并使用如下查询?
SELECT ID,Column1,Column2 FROM MyTable WHERE ID IN (@IDArray)
Run Code Online (Sandbox Code Playgroud)
如果重要的是我在VB.Net中使用SQL Server 2000
t-sql vb.net language-features sql-injection sql-server-2008
如果我#include <vector.h>输入我的源文件,我会收到此警告:
make -f Makefile CFG=Debug
g++ -c -g -o "Debug/mynn.o" "mynn.cpp"
In file included from C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/backward/vector.h:59,
from mynn.h:7,
from mynn.cpp:1:
**C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.**
g++ …Run Code Online (Sandbox Code Playgroud) 我是编程和Objective-C的新手,我正在尝试解决我的代码有什么问题.我已经阅读了一些关于块的内容,但我不知道到目前为止我所阅读的内容与我的代码有什么关系.
我的代码使用的是iOS 5 Twitter Framework.我使用Apple提供的大多数示例代码,所以我实际上一开始并不知道我使用了一个块作为完成处理程序.
现在我从Xcode 4获得了这两条消息:" 1.块将被捕获对象强烈保留的对象保留 ",并且" 在此块中捕获'自我'可能会导致保留周期 ".
基本上,我所做的是删除Apple在其完成处理程序中使用的代码(使用TWTweetComposeViewControllerResultCancelled和TWTweetComposeViewControllerResultDone的switch语句)并使用我的if语句[imagePickerController sourceType].
因此,sendTweet在将图像添加到推文后调用.
我希望有人可以向我解释为什么会这样,以及我如何解决它.另外:我可以将完成处理程序代码放入方法而不是块中吗?
- (void)sendTweet:(UIImage *)image
{
//adds photo to tweet
[tweetViewController addImage:image];
// Create the completion handler block.
//Xcode: "1. Block will be retained by an object strongly retained by the captured object"
[tweetViewController setCompletionHandler:
^(TWTweetComposeViewControllerResult result) {
NSString *alertTitle,
*alertMessage,
*otherAlertButtonTitle,
*alertCancelButtonTitle;
if (result == TWTweetComposeViewControllerResultCancelled)
{
//Xcode: "Capturing 'self' strongly in this block is likely to lead to a retain cycle" …Run Code Online (Sandbox Code Playgroud) 请有人向我展示一个使用libxml解析一些HTML的简单示例.
#import <libxml2/libxml/HTMLparser.h>
NSString *html = @"<ul>"
"<li><input type=\"image\" name=\"input1\" value=\"string1value\" /></li>"
"<li><input type=\"image\" name=\"input2\" value=\"string2value\" /></li>"
"</ul>"
"<span class=\"spantext\"><b>Hello World 1</b></span>"
"<span class=\"spantext\"><b>Hello World 2</b></span>";
Run Code Online (Sandbox Code Playgroud)
1)假设我想解析name = input2的输入值.
应该输出"string2value".
2)假设我想解析class = spantext的每个span标记的内部内容.
应输出:"Hello World 1"和"Hello World 2".
我有一个包含链接的字符串.链接通常具有以下形式:
http://www.address.com/something#something
python中是否有一个函数可以从链接中删除"#something"?