错误:开始索引不能小于零 [英] Error: start index can not be less then zero

查看:157
本文介绍了错误:开始索引不能小于零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Substring(ImageName.LastIndexOf(".")).ToLower();
上面代码行中的错误:起始索引不能小于零

Substring(ImageName.LastIndexOf(".")).ToLower();
Error in above line of code: start index can not be less than zero

推荐答案

为什么不使用GetExtension?
Why don''t you use GetExtension?
IO.Path.GetExtension(Path)


索引减零为-1,表示此处未找到".

您的字符串不包含.".您应该检查找到的>=0索引,如果不是,则返回string.Empty.

是的,您应该按照Prera​​k的建议使用GetExtension.

—SA
Index less by zero is -1 indicating "not found" here.

Your string does not contain ".". You should check found index for >=0 and, if it is not the case, return string.Empty.

Yes, you should use GetExtension as Prerak advised.

—SA


是的 GetExtension 是扩展名,
仅当您将文件路径或带有扩展名的文件名保存在名为ImageName的变量中时,此方法才有效,但是如果仅保存图像名,则必须对其进行更正.

我认为您可能只保存文件名,因为这样
Substring(ImageName.LastIndexOf(".")).ToLower();
您也可以获取扩展名.
yes GetExtension is for extension,
this works only if you save the file path or file name with extension in your variable called ImageName, but if you save only image name, then you have to correct it.

i think you might be saving only file name because by this
Substring(ImageName.LastIndexOf(".")).ToLower();
you can get the extension name as well.


这篇关于错误:开始索引不能小于零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆