有什么好方法可以在"或"后分割字符串.?
喜欢
$string = "test.test" result = test
$string = "test doe" result = test
Run Code Online (Sandbox Code Playgroud)
当然我可以使用爆炸两次,但我相信这不是最好的解决方案;)
在过去的几天里,我一直在使用winforms玩MVP模式,只有一件事我不知道该怎么做.如何从另一个视图创建子窗体.这是一个有效的选择吗?
public class MyForm : IMainFormView
{
private MainFormPresenter pres;
public MyForm() { pres = new MainFormPresenter(this); }
//Event from interface.
public event EventHandler<EventArgs> LoadSecondForm;
public void SomeButtonClick()
{
LoadSecondForm(this, EventArgs.Empty);
}
}
public class MainFormPresenter
{
private IMainFormView mView;
public MainFormPresenter(IMainFormView view) {
this.mView = view;
this.Initialize();
}
private void Initialize() {
this.mView.LoadSecondForm += new EventHandler<EventArgs>(mView_LoadSecondForm);
}
private void mView_LoadSecondForm(object sender, EventArgs e) {
SecondForm newform = new SecondForm(); //Second form has its own Presenter.
newform.Load(); // Load the …Run Code Online (Sandbox Code Playgroud) 继这个问题之后,我发现自己一遍又一遍地编写以下代码:
SqlCommand command = new SqlCommand();
// Code to initialize command with what we want to do
using (SqlConnection connection = openConnection())
{
command.Connection = connection;
using (SqlDataReader dataReader = thisCommand.ExecuteReader())
{
while (dataReader.Read())
{
// Do stuff with results
}
}
}
Run Code Online (Sandbox Code Playgroud)
必须嵌套两个using语句是相当繁琐的.有没有办法告诉 SqlDataReader它拥有该命令,并告诉命令它拥有该连接?
如果有办法做到这一点,那么我可以编写一个可以这样调用的辅助方法:
// buildAndExecuteCommand opens the connection, initializes the command
// with the connection and returns the SqlDataReader object. Dispose of the
// SqlDataReader to dispose of all resources that were acquired
using(SqlDataReader …Run Code Online (Sandbox Code Playgroud) 我有包含在try/catch块中的代码.我使用typeof来确定是否定义了变量:
if (typeof (var) == 'string') {
//the string is defined
}
Run Code Online (Sandbox Code Playgroud)
但是,在try/catch块中使用它,跳转到catch部分而不是执行它所做的事情(如果定义了字符串,则执行某些操作).
如何在不激活异常的情况下检查是否定义了变量?
我需要测试FTP应用程序的丢包.我使用了Wireshark数据包嗅探器,我得到了TCP Stream.
如何使用Wireshark找到丢包?
任何人都可以为emacs中的主要模式提供一个hello world示例吗?我想这是一个初学者的问题,我仍然非常想写一个主要的模式,既学习emacs又学习elisp,以便能够充分利用自定义.
到目前为止我做了什么(并且正在工作):
(require 'sample-mode)(provide 'sample-mode) 但它似乎没有被激活,我不能用M-sample-mode调用它.
那怎么办呢?谁能为我提供一个非常简单的Hello World,就像工作样本一样?
我在Windows 7上使用IIS Web服务器7.5来托管我的项目.我尝试创建Javascript和CSS处理程序,可以优化和压缩Javascript和Css文件大小.但我发现了一些问题.请查看我在Firefox 3.0.11浏览器上的Firebug中找到的Test.css文件的以下请求和响应.
响应标题
Cache-Control : private
Content-Type : text/html
Content-Encoding : gzip
Server : Microsoft-IIS/7.5
X-AspNet-Version : 2.0.50727
X-Powered-By : ASP.NET
Date : Tue, 30 Jun 2009 10:46:15 GMT
Content-Length : 197
Run Code Online (Sandbox Code Playgroud)
请求标题
Host : localhost
User-Agent : Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 (.NET CLR
4.0.20506)
Accept : text/css,*/*;q=0.1
Accept-Language : en-us,en;q=0.5
Accept-Encoding : gzip,deflate
Accept-Charset : ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive : 300
Connection : keep-alive
If-Modified-Since : Tue, 30 Jun 2009 10:41:00 …Run Code Online (Sandbox Code Playgroud) 如何在Linux命令行上解析CSV文件?
做以下事情:
csvparse -c 2,5,6 filename
Run Code Online (Sandbox Code Playgroud)
从所有行中提取第2,5和6列的字段.
它应该能够处理csv文件格式:http://tools.ietf.org/html/rfc4180这意味着引用字段并根据需要转义内部引号,因此对于包含3个字段的示例行:
field1,"field, number ""2"", has inner quotes and a comma",field3
Run Code Online (Sandbox Code Playgroud)
所以,如果我请求上面一行的字段2,我得到:
field, number "2", has inner quotes and a comma
Run Code Online (Sandbox Code Playgroud)
我很欣赏有很多解决方案,Perl,Awk(等)来解决这个问题,但我想要一个本机bash命令行工具,它不需要我调用其他脚本环境或编写任何其他代码(!).
在多线程编程上经历许多资源时,通常会出现对volatile说明符的引用.很明显,使用此关键字并不是在C/C++和Java(版本1.4及更早版本)中实现多个线程之间同步的可靠方法.以下是维基百科列出(不解释如何)作为此说明符的典型用法: -
我可以开始在上面列出的用法中看到这个说明符的作用,但由于我还没有完全理解这些区域中的每一个,我无法弄清楚这个说明符在每个用法中的行为.
有人能解释一下吗
我开发了一个Windows服务来在目录中编写PDF文件.该服务将文件写入本地驱动器没有问题.但是当它尝试写入网络映射驱动器时,它会失败并将该文件写入应用程序目录中.