我有一个哈希条目数组,并希望根据传递给函数的参数进行过滤.
如果有哈希三个值A,B和C,我想要做类似的东西:
data = [{A:'a1', B:'b1', C:'c1'},
{A:'a1', B:'b2', C:'c1'},
{A:'a1', B:'b2', C:'c2'},
{A:'a2', B:'b1', C:'c1'},
{A:'a2', B:'b2', C:'c1'}]
data.find_all{ |d| d[:A].include?params[:A] }
.find_all{ |d| d[:B].include?params[:B] }
.find_all{ |d| d[:C].include?params[:C] }
Run Code Online (Sandbox Code Playgroud)
找到A =='a1'和B ='b2'的所有地方
所以对于上面我得到:{A:'a1',B:'b2',C:'c1'}和{A:'a1',B:'b2',C:'c2'}*put if/ elsestatements,喜欢params.has_key? 'B'做点什么.*每次将新类型的值添加到哈希映射时修改我的代码(比如现在我有'D').
注意:哈希的键是一个符号,但是值是一个字符串,我想做一个"包含"而不是"等于".
我认为它是SQL Select语句,其中包含零或更多'=='子句
我正在尝试编写一个小的客户端服务器程序。服务器使用C#,客户端使用Java。以下是代码:
服务器:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.IO;
namespace Server
{
class Program
{
private TcpListener tcpListener;
public static void Main(string[] args)
{
Program program = new Program();
program.StartServer();
while (true) ;
}
private bool StartServer()
{
IPAddress ipAddress = Dns.GetHostEntry("localhost").AddressList[0];
try
{
tcpListener = new TcpListener(ipAddress, 5678);
tcpListener.Start();
tcpListener.BeginAcceptTcpClient(new AsyncCallback(this.ProcessEvents), tcpListener);
Console.WriteLine("Listing at Port {0}.", 5678);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
return false;
}
return true;
}
private void ProcessEvents(IAsyncResult …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个带有文件名的bash脚本,并返回包含一个单词的行.这是示例文本:
This has more than one word
There
is exactly one word in above line.
White-space
in the start of the above line doesn't matter.
Need-some-help.
Run Code Online (Sandbox Code Playgroud)
输出:
There
White-space
Need-some-help.
Run Code Online (Sandbox Code Playgroud)
我正在研究使用SED和Regex的组合.
注意:我不能使用任何其他东西(它必须是一个bash脚本,没有自定义模块),所以建议这样做无济于事.
当我运行以下查询时,我收到错误"无法将VARCHAR转换为FLOAT".问题是我的团队中的其他人设计了DB一段时间,并将毫秒作为varchar和sSometime值,因为他将"NA"改为"NA".
现在,当我将毫秒的值转换为AVE()时,"NA"无法生成.有没有办法为"NA"定义默认值,如:
IF a.Milliseconds == "NA"
0
ELSE
CAST(a.Milliseconds AS FLOAT)
SELECT
b.Date,
AVG(CAST(a.Milliseconds AS FLOAT)) AS Milliseconds,
FROM Fields a
INNER JOIN Cycles b
ON a.CyclesId = b.Id
GROUP BY b.Date
Sample Data
CyclesId | Milliseconds
1 | 24.1557
2 | 23.4886
3 | NA
Run Code Online (Sandbox Code Playgroud)