小编unw*_*guy的帖子

如何使用Boost正则表达式替换方法?

我有这些变量:

boost::regex re //regular expression to use
std::string stringToChange //replace this string
std::string newValue //new value that is going to replace the stringToChange depending on the regex.
Run Code Online (Sandbox Code Playgroud)

我只想替换它的第一次出现.

谢谢费拉斯.

编辑:我发现了这个:

boost::regex_replace(stringToChange, re, boost::format_first_only);
Run Code Online (Sandbox Code Playgroud)

但它说功能不存在,我猜这些参数目前是不正确的.

c++ boost boost-regex

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

Lua:如何确定元素是否是表而不是字符串/数字?

正如标题所说,我可以做什么功能或检查来确定lua元素是否是一个表?

local elem = {['1'] = test, ['2'] = testtwo}
if (elem is table?) // <== should return true
Run Code Online (Sandbox Code Playgroud)

lua lua-table

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

如何检查字符串是否包含空格/制表符/新行(任何空白的行)?

我知道有一个"isspace"函数可以检查空格,但这需要我遍历字符串中的每个字符,这可能会影响性能,因为这会被称为很多.有没有快速的方法来检查std :: string是否只包含空格?

例如:

function("       ") // returns true
function("    4  ") // returns false
Run Code Online (Sandbox Code Playgroud)

我想到的一个解决方案是使用正则表达式,然后我会知道它只包含空格,如果它是假的......但我不确定这是否比isspace函数更有效.

regex: [\w\W] //checks for any word character(a,b,c..) and non-word character([,],..)
Run Code Online (Sandbox Code Playgroud)

提前致谢!

c++

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

如何在不转义斜杠的情况下使用json_encode?

我是这样编码的..

json_encode($array_list, JSON_UNESCAPED_SLASHES)
Run Code Online (Sandbox Code Playgroud)

例如:\n变为\\n,\ r \n变为\\ r \\n

但是,它仍在逃避冲击!怎么了?怎么解决?谢谢.

php json escaping

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

如何从getMemberNames()修复JsonCPP错误?

JSON文件如下所示:

{
"strings": [
    {
        "key_one": "value_one!"
    },
    {
        "key_two": "value_two!"
    },
    ]
}
Run Code Online (Sandbox Code Playgroud)

C++文件如下所示:

Json::Value root;
Json::Reader reader;
bool parsingSuccessful = reader.parse(contents, root);
const Json::Value strings = root["strings"];
std::vector<std::string> list = strings.getMemberNames();
Run Code Online (Sandbox Code Playgroud)

"strings.getMemberNames()"引起的错误是:

Assertion failed: (type_ == nullValue || type_ == objectValue), function getMemberNames, file /projects/.../jsoncpp.cpp,
Run Code Online (Sandbox Code Playgroud)

strings是一个arrayValue,我通过它确认了它ValueType = 6.

c++ json jsoncpp

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

C++有一个类似于Objective-C的NSDictionary的字典吗?

正如标题所说,是否存在类似于Objective-C NSDictionaryfor C++ 的字典?我只需要一个包含(键,值)对的数据结构,并且可以添加和检索.

c++ cocoa dictionary objective-c nsdictionary

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

如何检查字符串是否全部为小写字母和字母数字?

有没有一种方法可以检查这些情况?或者我是否需要解析字符串中的每个字母,并检查它是否是小写(字母)并且是数字/字母?

c++ string alphanumeric lowercase

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

为什么我不能在Javascript函数中传递字符串作为参数?

我在php中有以下代码:

<?php
$apples = 123123;
echo "<td>
         <input type='button' onclick='confirmation($apples)' value='ac/in'>
      </td>";

echo('<script type="text/javascript">
           function confirmation(test) {
              var answer = confirm("Are you sure?")
              if (answer){
                  alert(test);
                  $.get("/index.php?f=func_name_to_call", 
                  {name: "John", hobby: "Programming"}, function(data) {});
              }
           }
</script>');
?>
Run Code Online (Sandbox Code Playgroud)

如果$ apples是一个数字,那么参数将被正确传递; 但是当它是一个字符串时,函数confirmation()被破坏.有任何想法吗?提前致谢.

javascript php arguments function

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

如何在 C++ 中将常量映射指针初始化为空?

一个简单的问题,我只想将一个映射初始化为空,而不是一个 nullptr。

 const std::map<std::string, std::string>* emptyDictionary;
Run Code Online (Sandbox Code Playgroud)

我试过

const std::map<std::string, std::string>* emptyDictionary = {"", ""};
Run Code Online (Sandbox Code Playgroud)

但显然这是不对的。谢谢你们。

c++ pointers map

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

Lua:如何检查字符串是否只包含数字和字母?

简单的问题可能有一个简单的答案,但我目前的解决方案似乎很可怕.

local list = {'?', '!', '@', ... etc)
for i=1, #list do 
    if string.match(string, strf("%%%s+", list[i])) then
         -- string contains characters that are not alphanumeric.
    end
 end
Run Code Online (Sandbox Code Playgroud)

有没有更好的方法来做到这一点..也许与string.gsub?

提前致谢.

lua alphanumeric non-alphanumeric pattern-matching

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

PHP:如何将文件导出到其他目录?

我是php的新手,我正在试图弄清楚如何将我的文件导出到另一个目录.到目前为止我有..

header("Content-Type: application/json");
header("Content-Disposition attachment; filename=\"test.text\"");
Run Code Online (Sandbox Code Playgroud)

我导出我的文件,但他们都去了下载,我怎样才能进入我/桌面?

提前致谢.

php desktop download

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