如何格式化获取的本地文本文件(文本格式的 C++ 代码)以在我的 contenteditable div 中正确格式化(就像粘贴事件所做的那样,这给我带来了所需的格式)。
function readSingleFile(evt) {
var f = evt.target.files[0];
console.log(f);
if (!f) {
alert("Failed to load file");
return;
}
if (f.name.indexOf('.txt') == -1) {
alert(f.name + " is not a valid text file.");
return;
}
var r = new FileReader();
r.onload = function(e) {
var contents = e.target.result.replace("\n","<br/>");
alert( "Got the file.n"
+"name: " + f.name + "n"
+"type: " + f.type + "n"
+"size: " + f.size + " bytesn"
+ "contents: " + contents
);
document.getElementById('board').innerHTML = contents;
}
r.readAsText(f);
}
document.getElementById('fileinput').addEventListener('change', readSingleFile, false);
http://jsfiddle.net/vinodlouis/88vtR/3/来自https://stackoverflow.com/users/2523444/vinod-louis
尝试将此字符串作为要打开的文本文件。它丢失了一些字符串,例如(由于不使用 html 实体?)
#include<iostream.h>
#include<conio.h>
int main(){
int grade, passingMark=75;
cout<<"Hi there, please enter your mark: ";
cin>>grade;
if( ((grade >= passingMark)||(grade==35)) && (grade<101)){
cout<<"\nPass!";
}
else if( (grade==74) ){
cout<<endl<<"Almost!";
}
else if( (grade>0) && (grade<70)){
cout<<endl<<"Super Failed!";
}
return 0;
}