C# code as below:
public static long ConvertStringToLong(string str)
{
str = str.Trim();
long m = 0;
int l = 1;
int startIndex = 0;
if (str[0] == '-')
{
l = -1;
startIndex++;
}
for (int i = startIndex; i < str.Length; i++)
{
m *= 10;
m += str[i];
}
return m * l;
}
本文介绍了一个C#中的实用函数,该函数用于将字符串转换为长整型数值。通过解析输入字符串并考虑负号的存在,此函数能够正确处理各种格式的数字字符串。
2841

被折叠的 条评论
为什么被折叠?



