大佬教程收集整理的这篇文章主要介绍了为什么我不能再用 cmd 编译 $,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我编写了一个代码来将一般的路径或文本“翻译”为 Git Bash 语法,当时我不知道我可以将它们放在 '' 中,在代码中我使用了 $ 特殊字符几个字符串,通过 csc filename.cs
在 cmd 上编译代码,它给了我 .exe 和它的所有伟大,今天我对代码做一些小改动,当我运行相同的代码来编译它给我:
GiTranslator.cs(59,62): error CS1056: Unexpected character '$'
GiTranslator.cs(71,25): error CS1056: Unexpected character '$'
GiTranslator.cs(72,25): error CS1056: Unexpected character '$'
GiTranslator.cs(73,25): error CS1056: Unexpected character '$'
所以,为什么?我该怎么做才能解决这个问题?
注意:细微的变化实际上只是评论中的一些拼写。
编辑1:如所问,代码(可能很糟糕,抱歉):
using System;
using System.Collections.Generic;
using System.linq;
using System.Text;
using System.Threading.Tasks;
using System.windows.Forms;
namespace Git_Path_Translator
{
class Program
{
#region Functions
static voID actuallyresetcolors()
{
Console.BACkgroundcolor = Consolecolor.black;
Console.Foregroundcolor = Consolecolor.White;
Console.Clear();
Console.Write(".");
Console.Clear();
}
#endregion
#region Global Variables
static String path;
static bool repetTranslation;
static bool repetAfterExcep;
#endregion
[STAThread] // don't kNow what it does,but its needed,classic right?
static voID Main(String[] args)
{
Console.BACkgroundcolor = Consolecolor.DarkCyan;
Console.Foregroundcolor = Consolecolor.Yellow;
Console.title = "Path Translator for Git Bash - by Tom ZamaTaro"; // just some credit to me,that no one is going to see,classic right?
Console.Clear();
// set up for the API loop
do
{
repetTranslation = false;
path = "";
Console.Writeline("\n Inform the path you would like to translate to Git Bash Syntax:");
Console.Write("\n "); // just for aesthetics,class... sory,no more classic joke tho,right? yes,I've a lot of shit in my head
// set up for the exception handling loop
do
{
repetAfterExcep = false;
try
{
if (path == "")
{
path = Console.Readline();
}
#region The Translation
String[] MetaChars = new String[] { @"\"," ","<",">","&",";","*","?","#",".","~","|","!","$","(",")","[","]","{","}","'","\"" }; // the Meta characters that I've to deal with
foreach (String Meta in MetaChars)
{
// BACkslash is the special case in this contex
if (Meta == @"\") { path = path.replace(Meta,"/"); }
// the rest
else { path = path.replace(Meta,$@"\{Meta}"); }
}
path = path.Trim(new char[] { '\'','"' }); // jusr making sure,...,what? I dIDn't say anything
/*
* the fist way I dID,yes,much worse,you kNow alredy,right?
* path = path.Trim().replace(@"\","/").replace(" ",@"\ ").replace("(",@"\(").replace(")",@"\)"); // taking of the spaces and putTing '\' where its needed
* path = path.replace("[",@"\[").replace("]",@"\]").replace("{",@"\{").replace("}",@"}]").Trim('"'); // nor sure if
*/
#endregion
Clipboard.SetText(path); // coPing it to the user's clipboard
Console.Writeline
(
$"\n The path was translated to:" +
$"\n\n {path}" +
$"\n\n and it is alredy copIEd to your clipbord."
); // just a bit more of aestheticness,yeah,go on conTinue throught the code
}
catch (ArgumentNullException)
{
Console.Clear();
Console.Writeline("\n Please inform a non-null value so the translation is possible," +
"\n if you would like to finish the solution,press enter:");
Console.Write("\n "); // same thing as before,just for aesthetics
if ((path = Console.Readline()) == "")
{
// dIDn't want to a valID translation
actuallyresetcolors(); // Console.resetcolor() isn't all that great on doing its job,so,yeah
Console.Write("\n "); // aesthetic for VS console
Environment.Exit(0);
}
else { repetAfterExcep = true; } // dID want to do a valID translation
}
} while (repetAfterExcep); // exception handling loop
Console.Write
(
"\n Type anything and press enter to make another translation,\n" +
" or press enter to finish the solution: "
); // asking for the loop
if (Console.Readline() == "")
{
// dIDn't want to do another translation
actuallyresetcolors(); // Console.resetcolor() isn't that great on doing its job,yeah
Console.Write("\n "); // aesthetics for VS console
Environment.Exit(0);
}
// dID want to do another translation
repetTranslation = true;
Console.Clear();
} while (repetTranslation); // API loop
}
}
}
编辑 2:也许有用的信息,我通常可以在 VS 上运行代码,但是当我尝试通过 csc filename.exe
编译它时,它给了我那个错误。
编辑 3:所以,
好吧,我不知道该怎么想或说什么。
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的为什么我不能再用 cmd 编译 $全部内容,希望文章能够帮你解决为什么我不能再用 cmd 编译 $所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。