字符串崩溃程序中的C#特殊字符(C# Special Characters in String Crashing Program)

编程入门 行业动态 更新时间:2024-10-28 05:22:14
字符串崩溃程序中的C#特殊字符(C# Special Characters in String Crashing Program)

我的路径有点问题:

"D:\\Music\\DJ Ti%C3%ABsto\\Tiesto\\Adagio For Strings (Spirit of London).mp3" "D:\\Music\\Dj Tiësto\\Tiesto\\Adagio For Strings (Spirit of London).mp3"

目前,当它将该路径发送到我的音频库时,它无法打开路径。 (它崩溃的原因是试图将-1分配给轨迹栏......但它无关紧要)。

所以我想知道,无论如何都要阻止C#用%[code]切换特殊字符? 我为“[”和“]”做了一个.Replace,但我不必查找每个特殊字符,并添加一行代码来防止它。 有没有办法解决?

I have a slight problem with a path:

"D:\\Music\\DJ Ti%C3%ABsto\\Tiesto\\Adagio For Strings (Spirit of London).mp3" "D:\\Music\\Dj Tiësto\\Tiesto\\Adagio For Strings (Spirit of London).mp3"

Currently, when it sends that path to my Audio Library, it cannot open the path. (the reason for it crashing is trying to assign a -1 to a trackbar...but it's irrelevant).

So I'm wondering, is there anyway to prevent C# from switching special characters with %[code]? I've done a .Replace for "[" and "]", but I rather not have to look up every single special character, and add a line of code to prevent it. Is there anyway around this?

最满意答案

调用Uri.UnescapeDataString 。

顺便说一下,当把路径放在字符串中时,你可以在字符串前放一个@符号来告诉编译器不要处理转义码,如下所示: @"D:\Music\DJ Tiësto\Tiesto\Adagio For Strings (Spirit of London).mp3" 。 这样,您不需要将每个反斜杠加倍。

Call Uri.UnescapeDataString.

By the way, when putting paths in strings, you can put an @ sign before the string to tell the compiler not to process escape codes, like this: @"D:\Music\DJ Tiësto\Tiesto\Adagio For Strings (Spirit of London).mp3". This way, you don't need to double up every backslash.

更多推荐

code,路径,path,电脑培训,计算机培训,IT培训"/> <meta name="description"

本文发布于:2023-07-30 01:35:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1321443.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   特殊字符   程序   Special   Program

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!