获取字符串VIN的最后4位# [英] Get string last 4 digits of VIN#
本文介绍了获取字符串VIN的最后4位#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在努力获取VIN#的最后4位数字。我认为这会很简单,但由于某些原因我得到了一个outofrange异常错误。
/ * * VIN的最后4位数#** /
string wholeVIN = record.vehicle.vehicleidentificationnumber;
string lastFourOfVIN = wholeVIN.Substring(wholeVIN.Length - 4 ,wholeVIN.Length-1 );
解决方案
如果您对此类简单任务有疑虑,请始终使用调试器。只需阅读有关您正在使用的文档: https:// msdn .microsoft.com / zh-CN / library / aka44szs%28v = vs.110%29.aspx [ ^ ]。
如你所见,第二个参数是子串长度,所以它应该是4.(但绝不硬编码立即常量如4)。
-SA
第二个参数是子串的长度!
尝试
/ * * VIN的最后4位#** /
string wholeVIN = record.vehicle.vehicleidentificationnumber;
string lastFourOfVIN = wholeVIN.Substring(wholeVIN.Length - 4 , 4 跨度>);
I am working on getting the last 4 digits of a VIN #. I thought it would be something simple but for some reason i am getting a outofrange exception error.
/** Last 4 digits of VIN # **/
string wholeVIN = record.vehicle.vehicleidentificationnumber;
string lastFourOfVIN = wholeVIN.Substring(wholeVIN.Length - 4, wholeVIN.Length-1);
解决方案
If you have concerns with such simple tasks, always use the debugger. And just read the documentation on what you are using: https://msdn.microsoft.com/en-us/library/aka44szs%28v=vs.110%29.aspx[^].
As you can see, the second parameter is the the sub-string length, so it should be 4. (But never hard-code immediate constants like 4.)
—SA
Second parameter is length of substring !
Try
/** Last 4 digits of VIN # **/ string wholeVIN = record.vehicle.vehicleidentificationnumber; string lastFourOfVIN = wholeVIN.Substring(wholeVIN.Length - 4, 4);
这篇关于获取字符串VIN的最后4位#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文