0

Just noticed that some strings (taken from an array created from a m3u playlist file) won't work due to a malformed hexadecimal character escape sequence.

var strArray =  [
"#EXTM3U",
"C:\music\X Marks the Pedwalk - Desolation.mp3", //fine
"#EXTINF:287,Xandria - Ginger Sunset Expire", //fine
"C:\music\andria - Ginger Sunset Expire.mp3", //fine
"C:\music\xandria - Ginger Sunset Expire.mp3", // FAILS
"C:\\music\\xandria - Ginger Sunset Expire.mp3" //fine
]

alert (strArray);

I can get around it with escape slashes. But my question is what is actually causing the error. I thought it might be something to do with \x but that would mean the first track would also fail. So I'm a little bit confused.

4

2 に答える 2

3

I thought it might be something to do with \x but that would mean the first track would also fail.

No, because x and X are not the same character. :-) \x (with the x in lower case) is special in string literals, \X (with the X in upper case) is not.

Best practice is to always escape backslashes that are meant to really be backslashes as opposed to the beginning of an escape sequence. Otherwise, you will trip yourself up.

于 2013-01-27T10:25:43.740 に答える