我已经在C#中实现了代码,我将此字符串传递//Comment
给了函数。为什么函数返回true?
bool function(string buf){
// split buffer from "//" and avoid from comment
string[] lineSplit = buf.Split(new string[] { "//" }, StringSplitOptions.None);
// split part of string from space and tab, and put into buffer
if (lineSplit[0] != null)
{
return true;
}
return false;
}
请帮我。
字符串拆分方法将具有第一个元素,String.Empty
就像分隔符出现在字符串的开头一样。你可以在这里阅读
您可能希望将检查null的if语句更改为以下形式:
bool function(string buf){
// split buffer from "//" and avoid from comment
string[] lineSplit = buf.Split(new string[] { "//" }, StringSplitOptions.None);
// split part of string from space and tab, and put into buffer
if (lineSplit[0] != string.Empty)
{
return true;
}
return false;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句