问题列表 - 第36263页

正则表达式,我需要改进一种从图像中获取src和alt的方法

分别获取src或alt是没有问题的,但是如何在每个具有组名的同时获得两者.

我们必须记住,alt可以在src的左侧或右侧.

我赶时间,所以我找到了一个快速解决方案,为src和alt创建了3个组名.我知道我们可以做得更好.

private void GetFirstImage(string newHtml, out string imgstring, out string imgalt)
{
    imgalt = "";
    imgstring = "";

    string pattern = "(?<=<img(?<name1>\\s+[^>]*?)src=(?<q>['\"]))(?<url>.+?)(?=\\k<q>)(?<name2>.+?)\\s*\\>";

    try
    {
        //si hay imagen
        if (Regex.IsMatch(newHtml, pattern))
        {
            Regex r = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Compiled);

            imgstring = r.Match(newHtml).Result("${url}");
            string tempalt = "", tempalt2;
            tempalt = r.Match(newHtml).Result("${name1}");
            tempalt2 = r.Match(newHtml).Result("${name2}");

            //ya tenemos la ruta de la imagen y de lo que aparece a izq y a derecha dentro de <img>

            try
            {
                pattern = "alt=(?<q>['\"])(?<alt>.+?)(?=\\k<q>)"; …
Run Code Online (Sandbox Code Playgroud)

.net c# regex

3
推荐指数
1
解决办法
389
查看次数

走响应链以传递自定义事件.这是错的吗?

根据iOS文档,响应者链用于"向上传递"触摸事件.它也用于控件生成的操作.精细.

我真正想做的是发送自定义事件"上链".接收事件的第一响应者将处理它.这似乎是一个非常常见的模式,但我找不到任何关于如何做到"iOS/Cocoa方式"的好解释.

由于响应链正是我所需要的,我提出了这样的解决方案:

// some event happened in my view that 
// I want to turn into a custom event and pass it "up":

UIResponder *responder = [self nextResponder];

while (responder) {

   if ([responder conformsToProtocol:@protocol(ItemSelectedDelegate)]) {
       [responder itemSelected:someItem];
       break;
   } 

   responder = [responder nextResponder];
}
Run Code Online (Sandbox Code Playgroud)

这很有效,但我觉得应该有其他方法来处理这个问题.手动走链子这种方式似乎不太好......

请注意,通知在这里不是一个好的解决方案,因为我只希望参与视图层次结构中的对象,并且通知是全局的.

在iOS中处理这个问题的最佳方法是什么(和Cocoa一样)?

编辑:

我想要完成什么?

我有一个视图控制器,它有一个视图,有子视图等...几个子视图是一个特定类型,显示数据库中的项目.当用户点击此视图时,应将信号发送到控制器以导航到此项目的详细信息页面.

处理点击的视图位于视图层次结构中主视图下方的几个级别.我必须告诉控制器(或在某些情况下,特定的子视图"向上链")选择了一个项目.

听通知是一种选择,但我不喜欢这种解决方案,因为选择一个项目不是全局事件.它严格依赖于当前的视图控制器.

iphone events cocoa ios

18
推荐指数
3
解决办法
7799
查看次数

是否可以通过其他应用程序使用TrueCrypt?(C#)

我刚刚开始使用TrueCrypt,我想知道我是否可以编写一个控制台/表单应用程序,允许我与truecrypt进行交互.它将在Windows 7的Visual Studio 2010中使用C#.我只是想知道我是否可以这样做.如果有人以前做过或知道是否有可能我会感激一些意见.

谢谢,

斯图尔特.

c# security truecrypt windows-7

4
推荐指数
1
解决办法
2700
查看次数

Ruby Rack - 安装一个简单的Web服务器,默认读取index.html

我正在尝试从本教程中获取一些信息:http://m.onkey.org/2008/11/18/ruby-on-rack-2-rack-builder

基本上我想要一个config.ru告诉机架读取当前目录的文件,这样我就可以像一个简单的apache服务器一样访问所有文件,并且还可以使用index.html文件读取默认的根...有什么方法可以做到这一点?

我目前config.ru看起来像这样:

run Rack::Directory.new('')
#this would read the directory but it doesn't set the root to index.html


map '/' do
  file = File.read('index.html')
  run Proc.new {|env| [200, {'Content-Type' => 'text/html'}, file] }
end
#using this reads the index.html mapped as the root but ignores the other files in the directory
Run Code Online (Sandbox Code Playgroud)

所以我不知道怎么从这里开始......

我也按照教程示例尝试了这个但是thin没有正确启动.

builder = Rack::Builder.new do

  run Rack::Directory.new('')

  map '/' do
    file = File.read('index.html')
    run Proc.new {|env| [200, {'Content-Type' => …
Run Code Online (Sandbox Code Playgroud)

ruby indexing webserver rack config

19
推荐指数
3
解决办法
1万
查看次数

ack或grep正则表达式匹配两条线,几乎相同

我正在查看我们的代码,看起来非常像:

#$foo="bar";
$foo="baz";
Run Code Online (Sandbox Code Playgroud)

问题:

  1. 我不知道变量的名称
  2. 我不知道哪条线实际被注释掉了.
  3. 我真的似乎无法正确编写多行正则表达式.

我最初的尝试是ack /\$(.\*)=.\*$\$($1)=/

我更喜欢ack代码grepping,但我也不介意使用grep.JWZ可能认为我现在有两个以上的问题.

regex grep

4
推荐指数
1
解决办法
2145
查看次数

使用linq截断文本

寻找一个简单的查询,使用Linq按x个字符截断文本.

c# linq

1
推荐指数
1
解决办法
2451
查看次数

如何在ASP.NET中使用User.Identity.Name作为SqlDataSource的参数?

对于SqlDataSource,我可以为传入参数配置外部源.例如,它可能是QueryString,Session,Profile等.但是我没有选择使用User作为源.

我知道我可以在插入,选择,更新,删除事件中为参数提供值.但我认为这不是一个优雅的解决方案,因为我已经在aspx文件中定义了一些参数.我不希望在两个单独的地方定义参数.它弄得一团糟.

那么我可以在.aspx文件中以某种方式定义此参数吗?

    <SelectParameters>
        <asp:QueryStringParameter DefaultValue="-1" Name="ID" 
            QueryStringField="ID" />
        //User.Identity.Name goes here as a value for another parameter  
    </SelectParameters> 
Run Code Online (Sandbox Code Playgroud)

c# asp.net sqldatasource parameter-passing

10
推荐指数
1
解决办法
1万
查看次数

如何阻止Eclipse要求安装Subversive Connectors

我正在使用Eclipse Helios v3.6,每次启动时都会得到以下对话框.但我不使用颠覆.有谁知道怎么做这个停止?

颠覆连接器发现

eclipse subversive

19
推荐指数
2
解决办法
7761
查看次数

抛出与捕获的类型相同的C#异常?

为什么(如果有的话)这是一个坏主意?

class Program
{
  static void Main(string[] args)
  {
     try
     {
        throw new NotImplementedException("Oh dear");
     }
     catch (Exception ex)
     {
        throw NewException("Whoops", ex);
     }
  }

  // This function is the salient bit here
  public static Exception NewException(String message, Exception innerException)
  {
     return Activator.CreateInstance(innerException.GetType(), message, innerException) as Exception;
  }
}
Run Code Online (Sandbox Code Playgroud)

这里重要的一点是该函数创建了与"innerException"相同类型的异常.

我在想......"哦......发生了异常.我实际上无法在这里处理它,但我可以添加一些额外的信息,并重新抛出.也许是另一个处理程序,更高的调用链可以处理它."

一个恰当的例子可能是某种SQL错误.我可能无法在调用时处理异常,但可能希望添加一些额外的"上下文"信息,例如"我正在调用它,并传递它".

似乎将调用链作为最初引发的类型的异常传递回来可能是有用的,而不是"Exception"或"ApplicationException".我知道我可以创建自己的自定义异常类,但是当你已经有一个很好的特定异常时,它似乎没有增加任何东西.

当然,我可能错了.这可能是一件非常有用的事情......但是一个小小的声音暗示着没有.

-----编辑-----

为了辩论,请考虑以下两个函数的效果(使用上面的代码):

这......经常看到:

  static int SalesTotal(int customerNumber)
  {
     try
     {
        throw new DivideByZeroException(); // something you didn't expect
     }
     catch (Exception ex)
     {
        throw new ApplicationException("Unable …
Run Code Online (Sandbox Code Playgroud)

c# exception-handling

7
推荐指数
2
解决办法
1895
查看次数

为什么在VB.NET中传递"Me"ByRef是合法的?

刚才我震惊地发现以下是合法的(C#等价物绝对不是):

Class Assigner
    ''// Ignore this for now.
    Public Field As Integer

    ''// This part is not so weird... take another instance ByRef,
    ''// assign it to a different instance -- stupid but whatever. '
    Sub Assign(ByRef x As Assigner, ByVal y As Assigner)
        x = y
    End Sub

    ''// But... what's this?!?
    Sub AssignNew()
        ''// Passing "Me" ByRef???
        Assign(Me, New Assigner)
    End Sub

    ''// This is just for testing.
    Function GetField() As Integer
        Return Me.Field
    End Function
End Class …
Run Code Online (Sandbox Code Playgroud)

vb.net compiler-construction byref this-pointer

4
推荐指数
2
解决办法
2154
查看次数