如何使用子字符串分割字符串 [英] How to split string using Substring

查看:157
本文介绍了如何使用子字符串分割字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像'/ Test1的/ Test2的'一个字符串,我需要采取的Test2来自同一分开。我该怎么做,在C#

I have a string like '/Test1/Test2', and i need to take Test2 separated from the same. How can i do that in c# ?

推荐答案

试试这个:

string toSplit= "/Test1/Test2";

toSplit.Split('/');

toSplit.Split(new [] {'/'}, System.StringSplitOptions.RemoveEmptyEntries);



分裂,后者将删除空字符串。

to split, the latter will remove the empty string.

添加。去年()将让你的最后一个项目。

Adding .Last() will get you the last item.

例如

toSplit.Split('/').Last();

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

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