简体   繁体   English

JavaScript slice() 使用 Github 站点在本地工作与在线工作不同

[英]JavaScript slice() working differently locally than online using Github site

I'm parsing text file using Javascript.我正在使用 Javascript 解析文本文件。 On the lines I have slice() function, my code appear to behave differently on local host and online在我有slice() function 的行上,我的代码在本地主机和在线上的行为似乎不同

for example例如

if(connection == 'local') {
     value = d.substring(split2, split3).substr(1).slice(0, -1);
}
else if(connection == 'online') {
     value = d.substring(split2, split3).substr(1);
}

However this piece of code solve it but I cannot understand the behavior, it seems like when I use my code online that are extra hidden characters on the text file or something然而,这段代码解决了它,但我无法理解这种行为,似乎当我在线使用我的代码时,这些代码是文本文件或其他东西上的额外隐藏字符

you can do你可以做

value = d.substring(split2, split3).substr(1).trim(); 

trim() should remove any spaces and Escape Sequences. trim()应该删除所有空格和转义序列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM