[英]Error CS1002 At Run Time - Markdown Parser (Headers Only)
"src/Solution.cs(9,12): error CS1002: ; expected" “src/Solution.cs(9,12):错误 CS1002:;预期”
I cannot work out why I am being shown this error?我无法弄清楚为什么我会看到这个错误? I have put my code below.我把我的代码放在下面。 I am very inexperienced at c-sharp, I normally work in c++, so maybe a small syntax error somewhere?我对 c-sharp 非常缺乏经验,我通常在 c++ 工作,所以可能是某个地方的小语法错误?
public class Challenge
{
public static string MarkdownParser( string markdown )
{
string inputText = markdown;
string outputText;
unsigned int indexOfFirstSpace = 0;
unsigned int inputTextLength = 0;
//Trim Spaces Before & After String
inputText = inputText.Trim();
if (inputText.StartsWith("#")){
//Find Index oF First Space & Store
indexOfFirstSpace = inputText.IndexOf(" ");
if (indexOfFirstSpace > 6){
return inputText;
}
else{
//Find Length Of Input String
inputTextLength = inputText.Length;
//Store Hashes In Own String
string hashes = inputText.Substring(0, indexOfFirstSpace);
//Store header text in string
string headerText = inputText.Substring(indexOfFirstSpace,(inputTextLength - indexOfFirstSpace));
//Trim Spaces From Front
headerText = headerText.TrimStart();
//Build Output
outputText = "<h" + indexOfFirstSpace + ">" + headerText + "</h" + indexOfFirstSpace + ">";
return outputText;
}
}
else {
return inputText;
}
}
}
There are 2 problems here:这里有2个问题:
You tried to use 'unsigned int'.您尝试使用“无符号整数”。 in C# the keyword for that is uinit.在 C# 中,关键字是 uinit。
The returned type for inputText.Length is actually an int, so the fixed code should be: inputText.Length的返回类型实际上是一个int,所以固定代码应该是:
public class Challenge { public static string MarkdownParser(string markdown) {公共 class 挑战 { 公共 static 字符串 MarkdownParser(字符串降价) {
string inputText = markdown; string outputText; // ---- Changed these variables to Int ---- int indexOfFirstSpace = 0; int inputTextLength = 0; //Trim Spaces Before & After String inputText = inputText.Trim(); if (inputText.StartsWith("#")) { //Find Index oF First Space & Store indexOfFirstSpace = inputText.IndexOf(" "); if (indexOfFirstSpace > 6) { return inputText; } else { //Find Length Of Input String inputTextLength = inputText.Length; //Store Hashes In Own String string hashes = inputText.Substring(0, indexOfFirstSpace); //Store header text in string string headerText = inputText.Substring(indexOfFirstSpace, (inputTextLength - indexOfFirstSpace)); //Trim Spaces From Front headerText = headerText.TrimStart(); //Build Output outputText = "<h" + indexOfFirstSpace + ">" + headerText + "</h" + indexOfFirstSpace + ">"; return outputText; } } else { return inputText; } }
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.