I must be completely blind or dumb in a different way, but when I write a string into a file, read it back into another string and then compare both strings with "!==", they are reported as different!
Then, if I compare them character by character, no difference is found (as expected).
const Storage = require('Storage');
function compareStrings (Original,Candidate) {
let OriginalLength = Original.length;
let CandidateLength = Candidate.length;
if (CandidateLength > OriginalLength) {
print('>>>> more characters read than written');
print('>>>> first additional character: ' + Candidate.charCodeAt(OriginalLength));
return;
}
if (CandidateLength < OriginalLength) {
print('>>>> less characters read than written');
print('>>>> first missing character: ' + Original.charCodeAt(CandidateLength));
return;
}
for (let i = 0; i < OriginalLength; i++) {
if (Original[i] !== Candidate[i]) {
print('>>>> different characters read than written');
print('>>>> first mismatch at #' + i + ': expected ' + Original.charCodeAt(i) + ', got ' + Candidate.charCodeAt(i));
return;
}
}
print('>>>> same characters read as written');
}
const FileContent_1 = 'this file exists for testing purposes only';
const FileContent_2 = 'this file still exists for testing purposes only';
if (Storage.write('4testing',FileContent_1)) {
print('file "4testing" was successfully created');
} else {
print('file "4testing" could not be written');
}
if (Storage.read('4testing') !== FileContent_1) {
print('contents of file "4testing" do not look as expected');
print('(namely "' + Storage.read('4testing') + '")');
compareStrings(FileContent_1,Storage.read('4testing'));
}
if (Storage.write('4testing',FileContent_2)) {
print('file "4testing" was successfully overwritten');
} else {
print('file "4testing" could not be overwritten');
}
if (Storage.read('4testing') !== FileContent_2) {
print('contents of file "4testing" do no longer look as expected');
print('(namely "' + Storage.read('4testing') + '")');
compareStrings(FileContent_2,Storage.read('4testing'));
}
Storage.erase('4testing');
print('file "4testing" has finally been deleted');
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Good morning!
I must be completely blind or dumb in a different way, but when I write a string into a file, read it back into another string and then compare both strings with "!==", they are reported as different!
Then, if I compare them character by character, no difference is found (as expected).
Does anybody have a solution for this puzzle?
The gist may be directly loaded and run on a connected watch through the IDE. Here comes the code: