控制台错误,需要删除特定字符

Console Error, need to remove a specific character

我知道标题可能令人困惑,但我的问题似乎很简单。

我正在尝试删除特定字符“#”。

This is how it currently logs (Click Here = Image) 我试图简单地删除“#”字符,这样当它登录到控制台时,文本前面不会有#。

我试过在休息前添加这个。

var 颜色 = stroke.split("#"); 但它没有用。

这是我的代码

xhr = new XMLHttpRequest();
xhr.open("GET", "http://colorillo.com/byjy.inline.svg");
xhr.addEventListener("load", function() {
const xmlDoc = new DOMParser().parseFromString(
    this.responseText.trim(),
    "image/svg+xml"
);
// Get all polylines as strings
let lines = xmlDoc.getElementsByTagName('polyline');
// Loop over all lines
for(let line of lines) {
    // --- OPTIONAL START ---

    //See Bruce'es comment (rgb() as output)
    let stroke = line.style.stroke;
    //let size = line.style.stroke-width;  -- Disabled
    // --- OR ---

    // Loop over all styles of this line (output same as input [hex])
    for(let style of line.getAttribute('style').split(';')) {
        // Get name & value
        let valueOffset = style.indexOf(':');
        // Check if name equal to 'stroke'
        if(style.substr(0, valueOffset).trim() === 'stroke') {
            // Save stroke value
            stroke = style.substr(valueOffset + 1).trim();
            // Break out of the loop (we don't have to search further)
            stroke.split("#"); // Here is what I've tried.
            break;
        }
    }
    console.log(stroke)
}
});
xhr.send();

将stroke.split("#")改为

stroke.replace('#','');

这将删除字符串中的第一个“#”。

您可以通过添加

来确认
console.log('BEFORE: '+stroke);

在那行之前,并且

console.log('AFTER: '+stroke);

在它之后。然后在 Dev Tools(或等效工具)中检查 console.log 输出。