问题列表 - 第43008页

Python使用正则表达式和replace()查找某些字符之间的子字符串

假设我有一个包含大量随机内容的字符串,如下所示:

strJunk ="asdf2adsf29Value=five&lakl23ljk43asdldl"
Run Code Online (Sandbox Code Playgroud)

而且我有兴趣获得位于'Value ='和'&'之间的子串,在这个例子中它将是'5'.

我可以使用如下的正则表达式:

 match = re.search(r'Value=?([^&>]+)', strJunk)
 >>> print match.group(0)
 Value=five
 >>> print match.group(1)
 five
Run Code Online (Sandbox Code Playgroud)

为什么match.group(0)是整个'Value = five'而group(1)只是'five'?我有办法让'五'成为唯一的结果吗?(这个问题源于我对正则表达式的一种微弱的把握)

我也将不得不在这个字符串中进行替换,如下所示:

 val1 = match.group(1)
 strJunk.replace(val1, "six", 1)    
Run Code Online (Sandbox Code Playgroud)

产量:

 'asdf2adsf29Value=six&lakl23ljk43asdldl'
Run Code Online (Sandbox Code Playgroud)

考虑到我计划一遍又一遍地执行上述两个任务(在'Value ='和'&'之间找到字符串,以及替换该值),我想知道是否还有其他更有效的方法来寻找substring并在原始字符串中替换它.我很好地坚持我所拥有的,但我只是想确保如果有更好的方法,我不会花费更多的时间.

python regex string replace

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

在列表框中选择时,WPF会更改datatemplate的可视状态

如果我有一个包含自定义用户控件ListBox的基本WPF ,ItemTemplate我如何告诉用户控件在DataTemplate更改其视觉状态时选择ListBox

非常感谢您提供的任何帮助

c# wpf listbox visualstatemanager

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

F#记录是否支持循环引用A - > B - > A?

我想使用F#记录,记录Race和Runner,其中Race引用Runner和Runner引用Race.这与Record一样可以和常规课一样吗?

type Race = {
  raceIdentifier : int
  carriedWeightMean : decimal
  prizeMoneyPercentileCountry : int64
  noOfHorses : int
  runners : Runner list
} 

type Runner = {
  horseId : int
  finishPositionSequence : int64
  lbw : decimal
  horseNumberOfRaces : int
  mutable race : Race
}
Run Code Online (Sandbox Code Playgroud)

我尝试过使用"with"关键字,但这似乎不起作用:

type Race = {
  raceIdentifier : int
  carriedWeightMean : decimal
  prizeMoneyPercentileCountry : int64
  noOfHorses : int
  race : Race
} with Runner = {
  horseId : int
  finishPositionSequence : int64
  lbw : decimal
  horseNumberOfRaces : int …
Run Code Online (Sandbox Code Playgroud)

f# data-structures

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

连接到mysql服务器(localhost)非常慢

实际上它有点复杂:

摘要:与DB的连接非常慢.

页面渲染大约需要10秒,但页面上的最后一个语句是一个回声,我可以在firefox中加载页面时看到它的输出(IE是相同的).在谷歌浏览器中,只有在加载完成后,输出才会变为可见.浏览器的加载时间大致相同.

在调试中我发现它的数据库连接正在产生问题.数据库在另一台机器上.进一步调试.我在本地计算机上部署了数据库..所以现在数据库连接在127.0.0.1但连接仍然需要很长时间.

这意味着问题在于APACHE/PHP而不是mysql.但后来我将我的代码部署在另一台远程连接数据库的机器上.一切似乎都很好.

基本上应用程序使用几个mod_rewrite ..但我删除了所有的.htaccess文件,缓慢的连接问题仍然存在..

我在我的机器上安装了另一个APACHE并使用了默认设置.连接仍然很慢.

我添加了以下语句来衡量执行时间

    $stime = microtime();  
    $stime = explode(" ",$stime);  
    $stime = $stime[1] + $stime[0];  

// my code -- it involves connection to DB

    $mtime = microtime();  
    $mtime = explode(" ",$mtime);  
    $mtime = $mtime[1] + $mtime[0]; 

    $totaltime = ($mtime - $stime);
    echo $totaltime;
Run Code Online (Sandbox Code Playgroud)

输出为0.0631899833679

但是firebug Net面板显示总加载时间为10-11秒.谷歌浏览器的情况也是如此

我试图关闭Windows防火墙..连接仍然很慢

我只是不能找到原因..我已经尝试了多个数据库服务器..多个apach ..似乎没有什么工作..任何想法可能是什么问题?

[编辑]

请仔细阅读评论部分了解更多详情.实际上我认为我即将获得解决方案.基本上我正在开发自己的框架,其中包括通过.htaccess文件重写URL.我添加了几个css和js文件,我注意到没有很好的理由(在Firefox中)为这些文件发送了多个请求.我认为这个问题与CONTENT-LENGTH标题有些相关,因为firefox没有收到这个标题所以它一直在等待内容(可能会有超时)..它与Transfer-Encoding有什么关系:chunked?

php mysql apache database-connection

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

在AJAX请求时禁用按钮

我试图在点击后禁用按钮.我试过了:

$("#ajaxStart").click(function() {
    $("#ajaxStart").attr("disabled", true);
    $.ajax({
      url: 'http://localhost:8080/jQueryTest/test.json',
      data: {
        action: 'viewRekonInfo'
      },
      type: 'post',
      success: function(response){
        //success process here                             
        $("#alertContainer").delay(1000).fadeOut(800);
       },
      error: errorhandler,
      dataType: 'json'
    });    
    $("#ajaxStart").attr("disabled", false);
});
Run Code Online (Sandbox Code Playgroud)

但按钮没有被禁用.当我删除$("#ajaxStart").attr("disabled", false); 按钮被禁用.

虽然这没有按预期工作,但我认为代码序列是正确的.任何帮助将不胜感激.

ajax jquery jquery-ui

30
推荐指数
2
解决办法
6万
查看次数

使用数字对std :: strings进行排序?

我目前正在使用std :: string <运算符进行排序.问题在于:

30 <9.30显示在9 <9之前,Windows 9x有此问题.我怎样才能在数字上对它们进行排序,以便在"9只狗"之后出现"30只狐狸".我还应该补充一点,我正在使用utf 8编码.

谢谢

c++ sorting string

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

通过单击菜单隐藏EditText并使其可见

我有一个布局与手机联系deatils.当我单击选项菜单时,我需要在该屏幕中显示一个edittext.我已经做了.但是有一个问题是编辑文本高度在屏幕不可见时被占用.如何删除编辑文本占用的空间,而它在屏幕(布局)中不可见..我的代码如下

我的xml是:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:paddingLeft="10dp"
    android:paddingRight="10dp">

    <ListView android:id="@id/android:list" android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:layout_weight="1"
        android:drawSelectorOnTop="false">
    </ListView>

    <TextView android:id="@id/android:empty" android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:text="No Entries available">
    </TextView>




    <TableRow android:id="@+id/TableRow001"
        android:layout_width="wrap_content" android:background="#C0C0C0"
        android:layout_height="wrap_content">

        <EditText android:id="@+id/NumberEditText01"

            android:layout_width="wrap_content"
            android:paddingLeft="20dip"
            android:layout_height="wrap_content">
        </EditText>

        <Button android:layout_width="wrap_content" android:id="@+id/callNow01"
            android:layout_height="wrap_content"
            android:text="Call now"
            >
        </Button>

    </TableRow>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

和班级:

public class ListContacts extends ListActivity {

    TableRow tableRow;
    EditText phoneNumber;
    Button callNow;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Associate the xml with the activity
        setContentView(R.layout.activitylist);
        tableRow = (TableRow) findViewById(R.id.TableRow001);
        tableRow.setVisibility(View.INVISIBLE); …
Run Code Online (Sandbox Code Playgroud)

android

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

如何仅为发布版本内联函数

// common.h
// This is foo function. It has a body.
__inline void foo() { /* something */ }

// a.cpp
#include "common.h" // for foo function
// Call foo

// b.cpp
#include "common.h" // for foo function
// Call foo
Run Code Online (Sandbox Code Playgroud)

我想在我为发布版本构建时内联foo函数.我不想内联函数进行Debug构建.

我试过了,但链接器错误让我烦恼.
在这种情况下,foo函数的主体在common.h头文件中定义.
所以,如果我这样做

//common.h
#if !defined(_DEBUG)
__inline
#endif
void foo() { /* something */ }
Run Code Online (Sandbox Code Playgroud)

它将在DEBUG构建中遇到链接错误.因为两个模块试图包含common.h.
我不知道要解决它.
可能吗?

c inline function c-preprocessor

3
推荐指数
2
解决办法
1371
查看次数

最后加载的iframe上的Fire事件

如何在一系列load事件中点击最后一些东西?我正在加载多个iframe,并且需要在所有iframe完成加载时触发一个函数.所以我需要将函数绑定到最后一个iframe加载的load事件.

这可能吗?如果可能的话,我不想强​​制同步加载.

javascript jquery

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

.net和c#的成熟BDD(行为驱动开发)框架

上次我在2009年底寻找一个框架,现在我想使用BDD,我发现.NET中有大约7个BDD框架,我想知道,根据某人的经验,哪一个是最多的成熟?

.net c# bdd

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