小编yop*_*mer的帖子

Javascript Blob anchortag下载产生损坏的文件

下面的代码下载了一个无法打开(损坏)的文件,我完全不知道为什么.我已经在很多方面尝试了这个但它永远不会工作,它总是会产生一个损坏的文件.原始文件不是问题,因为它打开正常.我正在尝试打开mp4,mp3和图像文件.

//$scope.fileContents是一个字符串

$scope.fileContents = $scope.fileContents.join(",");
        var blob = new Blob([$scope.fileContents], {type: $scope.file.fileDetails.type});
        var dlURL = window.URL.createObjectURL(blob);
        document.getElementById("downloadFile").href = dlURL;
        document.getElementById("downloadFile").download = $scope.file.fileDetails.name;
        document.getElementById("downloadFile").click();
        window.URL.revokeObjectURL(dlURL);
Run Code Online (Sandbox Code Playgroud)

javascript anchor blob file download

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

使用c ++功能解析字符串的最有效方法

这可能是一个愚蠢的问题(我希望不是),但它引起了我的注意,我正试图解决它.使用c ++功能解析字符串的最有效方法是什么?我很欣赏每个人的评论,因为我,我相信其他人也一样,成为更好的程序员!以下是我现在用现有知识做的事情:

#include <iostream>
#include <string>
using std::cout;
using std::string;
using std::endl;
void parseLine(string &line)
{
    constexpr char DELIMITER_ONE = '|';
    constexpr char DELIMITER_TWO = '[';
    for (int i = 0; i < line.length(); i++)
    {
        if (line[i] == DELIMITER_ONE || line[i] == DELIMITER_TWO)
        {
            line.erase(i, 1);
        }
    }
    cout << line << endl;
}
int main()
{
    std::string testString = "H|el[l|o|";
    parseLine(testString);

    system("pause");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ string parsing

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

标签 统计

anchor ×1

blob ×1

c++ ×1

download ×1

file ×1

javascript ×1

parsing ×1

string ×1