小编cod*_*ict的帖子

JavaScript正则表达式背后的正面看法

我有一份文件,我需要从中提取一些数据.文档包含这些字符串

Text:"How secure is my information?"
Run Code Online (Sandbox Code Playgroud)

我需要在文字后面提取双引号的文本 Text:

How secure is my information?
Run Code Online (Sandbox Code Playgroud)

如何在Javascript中使用正则表达式执行此操作

javascript regex

31
推荐指数
3
解决办法
4万
查看次数

如果我使用sizeof和size_t,我是否应该总是包含stddef.h

如果我使用sizeof运算符并size_t在我的代码中使用,我是否必须包含stddef.h?我没有包含stddef.h,我的代码在没有警告的情况下编译MVS2008和Borland C++ BuilderX.

非常感谢...

c sizeof size-t

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

在printf中为正数打印前导'+'

我有一个温度转换程序作为一项任务,我已经完成了.该程序中有许多printf声明可以打印温度.现在,负温度按照我想要的方式打印,但正面温度打印时没有前导+符号.

现在,printf打印+正数的最佳方法是什么?我能想到的只是改变

printf("Min temp = %d\n",max_temp)
Run Code Online (Sandbox Code Playgroud)

if(max_temp > 0)
    printf("+");
printf("Min temp = %d\n",max_temp)
Run Code Online (Sandbox Code Playgroud)

但这要求程序中的许多变化:(

另一个选择是编写我自己的打印功能并将此逻辑放在那里.你有什么建议?

c string format formatting printf

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

用&&​​返回

用&&​​返回值是什么意思?

else if (document.defaultView && document.defaultView.getComputedStyle) {

    // It uses the traditional ' text-align' style of rule writing, 
    // instead of textAlign
    name = name.replace(/([A-Z]) /g, " -$1" );
    name = name.toLowerCase();
    // Get the style object and get the value of the property (if it exists)
    var s = document.defaultView.getComputedStyle(elem, " ") ;
    return s && s.getPropertyValue(name) ;
Run Code Online (Sandbox Code Playgroud)

javascript return operators

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

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

char*str ="STRING"和char str [] ="STRING"之间的区别?

在编写一个简单的函数来从字符串中删除特定字符时,我遇到了这个奇怪的问题:

void str_remove_chars( char *str, char to_remove)
{
    if(str && to_remove)
    {
       char *ptr = str;
       char *cur = str;
       while(*ptr != '\0')
       {
           if(*ptr != to_remove)
           {
               if(ptr != cur)
               {
                   cur[0] = ptr[0];
               }
               cur++;
           }
           ptr++;
       }
       cur[0] = '\0';
    }
}
int main()
{
    setbuf(stdout, NULL);
    {
        char test[] = "string test"; // stack allocation?
        printf("Test: %s\n", test);
        str_remove_chars(test, ' '); // works
        printf("After: %s\n",test);
    }
    {
        char *test = "string test";  // non-writable?
        printf("Test: %s\n", …
Run Code Online (Sandbox Code Playgroud)

c arrays string stack pointers

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

Java String ReplaceAll方法给出非法重复错误?

我有一个字符串,当我尝试运行该replaceAll方法时,我收到这个奇怪的错误:

String str = "something { } , op";
str = str.replaceAll("o", "\n"); // it works fine
str = str.replaceAll("{", "\n"); // does not work
Run Code Online (Sandbox Code Playgroud)

我得到一个奇怪的错误:

Exception in thread "main" java.util.regex.PatternSyntaxException:
Illegal repetition {  
Run Code Online (Sandbox Code Playgroud)

我怎样才能替换出现的"{"

java regex string replaceall

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

如何在Perl中对数字进行排序?

print "@_\n";
4109 4121 6823 12967 12971 14003 20186
Run Code Online (Sandbox Code Playgroud)

我如何在Perl中对它进行排序?

使用@sorted = sort(@_);给我一个字母顺序

13041 13045 14003 20186 4109 4121 6823
Run Code Online (Sandbox Code Playgroud)

我如何获得数字排序?Perl是否具有用于合并排序,插入排序等的内置函数?

arrays sorting perl

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

在线性时间内旋转数组的算法

如何i使用swap函数仅在线性时间内按时间旋转整数数组.

arrays algorithm

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

用(\\?)替换问号(?)

我试图定义一个模式来匹配文本与其中的问号(?).在正则表达式中,问号被认为是"一次或根本没有".那么我可以用(\\?)替换我的文本中的(?)符号来修复模式问题吗?

String text = "aaa aspx?pubid=222 zzz";
Pattern p = Pattern.compile( "aspx?pubid=222" );
Matcher m = p.matcher( text );

if ( m.find() )
 System.out.print( "Found it." );
else
 System.out.print( "Didn't find it." );  // Always prints.
Run Code Online (Sandbox Code Playgroud)

java regex replace escaping

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