问题列表 - 第48372页

使用String.Format构建正则表达式:"输入字符串的格式不正确"

我正在构建文档从模板引擎.在某些时候,我需要在Reg Exp组上进行匹配,并将模板文本替换为db中的内容.

我最初硬编码了我的RegExp,做了类似的事情:

Regex r = new Regex(@"{DocSectionToggle::(?<ColumnName>\w+)::(?<ResponseValue>.+)}\n\[\[(?<SectionContent>.+)\]\]", RegexOptions.Multiline);
Run Code Online (Sandbox Code Playgroud)

道歉:它会进行群组捕获,因此语法不是最漂亮的.

只是为了让事情变得更整洁,因为我想'保持web.config或其他地方的模式,我'''''''''''''''''''''''''''''''''''

string _regexp_DocSectionToggle = @"{DocSectionToggle::{0}::{1}}\n\[\[{2}\]\]";

/* Reg Exp Patterns for group capture */

string _rxCol            = @"(?<{ColumnName}>\w+)";
string _rxResp           = @"(?<{ResponseValue}>.+)";
string _rxSectContent    = @"(?<{SectionContent}>.+)"; 

Regex r = new Regex( string.Format(_regexp_DocSectionToggle,
                                    _rxCol,
                                    _rxResp,
                                    _rxSectContent), 

                      RegexOptions.Multiline
                   );
Run Code Online (Sandbox Code Playgroud)

但我收到一个错误:'输入字符串格式不正确'.

谁能说出我的原因?这是一个限制string.Format(...)吗?

谢谢你的期待.

c# regex asp.net string.format

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

如何让resharper跳过生成的文件

Resharper真的抱怨像WCF服务引用之类的东西生成的reference.cs等文件.如何让Resharper完全跳过这些文件?

resharper

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

如何在iOS中获取音频文件的持续时间?

NSDictionary* fileAttributes = 
    [[NSFileManager defaultManager] attributesOfItemAtPath:filename 
                                                     error:nil]
Run Code Online (Sandbox Code Playgroud)

从文件属性键,您可以获得日期,大小等.但是如何获得持续时间?

audio duration file nsdictionary ios

44
推荐指数
5
解决办法
3万
查看次数

为什么我的C程序会输出这个?

我试图解决两个预处理器相关的问题,但在这两个程序中,我得到的结果是我无法弄清楚如何.以下是我的计划:

#include<stdio.h>
#define SQUARE(x) x*x
int main()
{
float s=10,u=30 ,t=2,a;
a=2*(s-u*t)/SQUARE(t);
printf("Result:%f\n",a);
return 0;
}
Run Code Online (Sandbox Code Playgroud)

据我说,这个程序的输出应该是,-25.000但我得到了-100.000.

在第二个程序中:

#define FUN(i,j) i##j
int main()
{
int val1 = 10;
int val12 = 20;
clrscr();
printf("%d\n",FUN(val1,2));
getch();
}
Run Code Online (Sandbox Code Playgroud)

输出应该是,102但我得到20; 为什么会这样?

c string-concatenation stringification c-preprocessor

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

如何在C ++中使用tagDEC(DECIMAL类型)?

我使用返回Windows DECIMAL类型的API。

我需要转换它,我需要的信息是:

  • 小数位数
  • 价值本身

例如,如果我的数字是1.234,我想得到0.01(2,1)等于10(0,10)等于(3,1234)。如何从tagDec对象提取此信息?

谢谢

c++ windows decimal

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

最近的jquery不想工作

我在页面上重复了一个带有div的图像,如下所示:

 <img src="/img/productspage/questionMark.jpg" class="prodQuestionMark" />
            <div class="vuQuestionBubble">
                <p>this is where text for the text will go</p>
            </div>
Run Code Online (Sandbox Code Playgroud)

vuQuestionBubble有一个样式显示:默认为none.当点击'prodQuestionMark'时,我希望它旁边的vuQuestionBubble显示.我把这个代码放在底部.

$(document).ready(function () {
    $('.prodQuestionMark').click(function () {

        $(this).closest('vuQuestionBubble').show();
    });
});
Run Code Online (Sandbox Code Playgroud)

它似乎不起作用... click事件正在工作,我可以用.parent选择父div但似乎无法与最近的div进行交互...任何想法?

javascript jquery closest

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

访问django模板中的元组

 t=[]
 t.append(("a",1))
 t.append(("b",2))
 t.append(("c",3))
 return render_to_response(t.html,  context_instance=RequestContext(request, {'t':t}))
Run Code Online (Sandbox Code Playgroud)

如果我想访问访问django模板中的值t而不使用for循环我该怎么办.我尝试了以下它似乎没有工作

    alert('{{t[a]}}');
    alert('{{t[c]}}');
Run Code Online (Sandbox Code Playgroud)

django django-templates django-models django-views

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

Web应用程序中的静态变量

我可以在Web应用程序中使用静态变量吗?什么是静态的替代品?当我在页面中使用静态变量并且多个用户使用该应用程序时,它会产生冲突数据(不正确的数据).

使用静态成员的限制是什么?

静态成员是否在内存中共享?

.net c# asp.net session static-members

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

RXTX串行连接 - 阻塞read()的问题

我试图使用RXTX库阻止Windows上的串行通信(XP和7).我已经在两端测试了与Hyperterminal的连接,并且它可以完美地工作.

我使用以下代码设置连接:(为清晰起见,省略了异常处理和防御性检查)

private InputStream inStream;
private OutputStream outStream;
private BufferedReader inReader;
private PrintWriter outWriter;
private SerialPort serialPort;
private final String serialPortName;

public StreamComSerial(String serialPortName) {
this.serialPortName = serialPortName;
CommPortIdentifier portIdentifier;
portIdentifier = CommPortIdentifier.getPortIdentifier(serialPortName);
CommPort commPort = null;
commPort = portIdentifier.open(this.getClass().getName(),500);
serialPort = (SerialPort) commPort;    serialPort.setSerialPortParams(4800,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
inStream = serialPort.getInputStream();
outStream = serialPort.getOutputStream();
inReader = new BufferedReader(new InputStreamReader(inStream, Settings.getCharset()));
outWriter = new PrintWriter(new OutputStreamWriter(outStream, Settings.getCharset()));
Run Code Online (Sandbox Code Playgroud)

我用的时候

outWriter.println("test message");
flush();
Run Code Online (Sandbox Code Playgroud)

在另一端收到的消息很好,但是打电话

inReader.readLine()
Run Code Online (Sandbox Code Playgroud)

imidiately返回"java.io.IOException:底层输入流返回零字节".

然后我决定尝试实现自己的阻塞读取逻辑并写下:

public String readLine() throws IOException {        
    String line = …
Run Code Online (Sandbox Code Playgroud)

java serial-port rxtx

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

如何在WPF中创建类似UserControl的ComboBox

我正在尝试构建一个能够从XAML中获取元素的usercontrol,如下所示:

            <ComboBox >
                <ComboBoxItem />
                <ComboBoxItem />
                <ComboBoxItem />
            </ComboBox>
Run Code Online (Sandbox Code Playgroud)

ComboBox,你可以只在ComboBox标签之间添加Items ,我想复制它,但我不知道从哪里开始.

完了它应该是这样的:

    <cis:ReportControl Grid.Row="3">
            <cis:ReportItem />
    </cis:ReportControl>
Run Code Online (Sandbox Code Playgroud)

cis:ReportControl,有一些Buttons和一个ComboBox,基本上我只想ComboBox用物品喂.

报告项目只是ComboBoxItem一些额外的属性.

编辑:

我已根据@Snowbears的答案实现了它,但现在的问题是控件本身就是一个项目.我认为这是因为我有一些内容,通过定义ContentProperty我的内容ComboBox,它被重定向到Box.我该怎么做才能避免这种情况?

编辑二:

它完全适用于此:

    private ItemCollection reportItems;
    public ItemCollection ReportItems
    {
        get
        {
            if (reportItems == null)
            {
                reportItems = this.ComboBoxReports.Items;
            }
            return reportItems;
        }
    }
Run Code Online (Sandbox Code Playgroud)

[ContentProperty("ReportItems")]属性.ComboBoxReports是Control中的ComboBox,我不得不继承ItemsControl它以使其工作.

wpf user-controls wpf-controls

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