使用C#修剪字符串 [英] Trim String using c#

查看:82
本文介绍了使用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

推荐答案

像这样:

like this:

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);


看看


您可以使用拆分功能.
然后根据需要对结果进行归类.
Hi,
you can use split function.
then concatinate the result according to your need.


这篇关于使用C#修剪字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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