Search code examples
javascriptxcodereact-nativemobileqr-code

I want to print the data as a list when the QR Code is scanned


There will be a special qr code and there will be sequential information in this qr code.Can I print the information in the incoming qr code on the bottom line when it sees a space or a symbol(@)?

https://www.hizliresim.com/qc4feyi ----- Screen output is undesirable

https://www.hizliresim.com/rkajsoy ----- Desired

https://www.hizliresim.com/lnd387j ----- Processes and permissions when scanned


Solution

  • Use \n for new line

    alert("Color@100@42@1$".replace(/@/g, "@\n"))

    After edit

    const text = "Color@100@42@1$".replace(/@/g, "@<br />");
    
    document.getElementById('text').innerHTML = text;
    <div id="text" />

    After edit : added labels

    const data = '@Red@Pros@42@1$'.split('@');
    const labels = ['Color', 'Shape', 'Weight', 'Price'];
    let text = data.map((item, i) => (item ? `${labels[i]}:${item}` : item));
    text = text.join('<br />');
    
    document.getElementById('text').innerHTML = text;
    <div id="text" />