Is there a Unicode character that acts like a backspace or is invisible?

386 Views Asked by At

I was messing around with strings of random Unicode characters. I generated two different string that both had the same length. They were both populated with random Unicode characters between 0 and 255. I noticed after I ran the program the length of one string was different than the other. Dose anyone know if there is an invisible character or character that deletes there character before it in Unicode?

//coded in javascript but the native language is Java
function generate(text) {
  //create an decode key array
  let decodeKey = [];
  for (let i = 0; i < text.length * 2; i++) {
    decodeKey.push(Math.floor(Math.random() * 10));
  }
  let binary = [];
  for (let i = 0; i < text.length; i++) {
    //turn text to binary and split at every 4th character
    let b = text.charCodeAt(i).toString(2);
    while (b.length < 8) {
      b = "0" + b;
    }
    binary.push(b.slice(0, 4));
    binary.push(b.slice(3));
  }
  //convert binary to a number and multiply by the decode key
  let nums = [];
  for (let i = 0; i < binary.length; i++) {
    nums.push(parseInt(binary[i].toString(10)) * decodeKey[i]);
  }
  //convert nums to unicode
  let uniChars = [];
  for (let i = 0; i < nums.length; i++) {
    uniChars.push(String.fromCharCode(parseInt(nums[i])));
  }
  //create final string with decode key at the bottom
  let result = "";
  for (let i = 0; i < uniChars.length; i++) {
    result += uniChars[i];
  }
  result += "\n"
  for (let i = 0; i < decodeKey.length; i++) {
    result += String.fromCharCode(decodeKey[i]);
  }
  //return the result
  return result;
}

console.log(generate("Test / Sample Text, Test / Sample Text, Test / Sample Text, Test / Sample Text"));

0

There are 0 best solutions below