本文介绍了使用C#修剪字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个像这样的字符串(VAN909_445_Viperacrfd_40450.jpg)
现在,我要删除该零件(Viperacrfd_40450.jpg). 445是一个id,我将能够从数据库中检索该数据,以便进行修整..谁能告诉我如何获得Viperacrfd_40450.jpg
I have a string with name like this (VAN909_445_Viperacrfd_40450.jpg)
Now i want to remove the part (Viperacrfd_40450.jpg). The 445 is an id and i''ll be able to retrieve from DB so that triming will be easier.. Can anyone tell me how to get the desired result of Viperacrfd_40450.jpg
推荐答案
string input = "VAN909_445_Viperacrfd_40450.jpg";
int Id = 445;
int index = input.IndexOf(string.Format("_{0}_", Id), 0);
string result = input.Remove(0, index + 2 + Id.ToString().Length);
这篇关于使用C#修剪字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!