小编pro*_*joy的帖子

C++:为什么正则表达式模式"[+ - /*]"匹配字符串"."?

我使用的正则表达式有什么问题?

#include<regex>
#include<iostream>
#include<string>
using namespace std;
int main(int argc,char *argv[])
{
    smatch results;
    string temp("[+-/*]");
    string test(".");

    regex r(temp);

    if(regex_search(test,results,r))
        cout<<results.str()<<endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

"" 将打印输出,如果我使用'\'创建转义序列,如:

string temp("[\\+-/\\*]");
Run Code Online (Sandbox Code Playgroud)

输出仍然存在.

c++ regex

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

Android:在新线程中使用改造时会发生NetworkOnMainThreadException吗?

我尝试使用改造库从一个分离的线程中的url下载文件(apk:2mB).

这是我的代码(参见教程:https://futurestud.io/blog/retrofit-2-how-to-download-files-from-server):

public class MainActivity extends AppCompatActivity {
    String fileUrl = ".....";


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        new Thread(new Runnable() {
            @Override
            public void run() {
                FileDownloadService downloadService = ServiceGenerator.createService(FileDownloadService.class);
                Call<ResponseBody> call = downloadService.downloadFileWithDynamicUrlSync(fileUrl2);

                call.enqueue(new Callback<ResponseBody>() {
                    @Override
                    public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                        if (response.isSuccessful()) {
                           writeResponseBodyToDisk(response.body());
                        } else {
                            Log.d("fail", "server contact failed");
                        }
                    }

                    @Override
                    public void onFailure(Call<ResponseBody> call, Throwable t) {
                        Log.e("fail", "error");
                    }
                });
            }
        }).start();
    }

    private …
Run Code Online (Sandbox Code Playgroud)

multithreading android retrofit

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

python初学者:'print mystr.split(',')出了什么问题.sort(reverse = True)'

我尝试从字符串中排序一个数字序列:

在python解释器中:

    >>> mystr = '1,2,3,4,5'
    >>> a = mystr.split(',')
    >>> a
    ['1', '2', '3', '4', '5']
    >>> a.sort(reverse=True)
    >>> a
    ['5', '4', '3', '2', '1']
Run Code Online (Sandbox Code Playgroud)

但是当我想缩短代码时,会出现问题:

    >>> mystr
    '1,2,3,4,5'
    >>> print mystr.split(',').sort(reverse=True)
    None
Run Code Online (Sandbox Code Playgroud)

为什么会这样?希望得到你的帮助!

python

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

标签 统计

android ×1

c++ ×1

multithreading ×1

python ×1

regex ×1

retrofit ×1