咋把网站制作成软件seo关键词教程
qt自动生成的ts文件内部就是用xml写的,可以直接用txt文档编辑器打开。想要使用该代码需要更换文件路径,使用前可以强制更改后缀名将ts文件改成txt文件。
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <iosfwd>
#include<sstream>int Split(const std::string& s, std::vector<std::string>& sv, const char delim, int maxSplit = 0) {sv.clear();std::istringstream iss(s);std::string temp;int splitCount = maxSplit == 0 ? INT_MIN : 0;while (std::getline(iss, temp, delim) && (splitCount++ < maxSplit)) {sv.emplace_back(std::move(temp));}return static_cast<int>(sv.size());
}int main() {std::string file_name{ "" };file_name = "D:Chinese.txt";std::ifstream in_file;in_file.open(file_name.c_str(), std::ios::binary);if (in_file.is_open()) {//打开输出文件file_name = "D:Chinese.csv";std::ofstream out_file;out_file.open(file_name.c_str(), std::ios::binary);if (out_file.is_open()) {std::string str;std::vector<std::string> str_data;std::vector<double> data;//循环读取ts文件并输出到csv中bool need_endl = false;while (std::getline(in_file, str)) {str_data.clear();Split(str, str_data, '<');//把多行翻译排除if (str_data.size() >= 3) {str = str_data[1];str_data.clear();Split(str, str_data, '>');if (str_data.size() >= 2) {if (str_data[0] == "source") {out_file << str_data[1] << ",";need_endl = true;}else {//判断是否包含tanslation关键字std::vector<std::string> str_trans_symbol;Split(str_data[0], str_trans_symbol, ' ');if (str_trans_symbol[0] == "translation") {//将翻译中包含的逗号转为空格std::vector<std::string> str_translation;Split(str_data[1], str_translation, ',');for (auto temp : str_translation){out_file << temp << " ";}out_file << std::endl;need_endl = false;}}}else {if (need_endl) {out_file << std::endl;need_endl = false;}}}else {if (need_endl) {out_file << std::endl;need_endl = false;}}}out_file.close();}in_file.close();}
}