如何获取字符串中字符的最后一次出现 [英] how to get the last occurence of a character in a string

查看:60
本文介绍了如何获取字符串中字符的最后一次出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 D:\ nageswararao\dec-14-12-night \ Alumini_App\Alumini_App\Resume\NN_dd.doc 



在上面的路径中,我需要找到''\''的最后一次出现,并且我希望将路径分成两个两个字符串。

解决方案

您可以使用 Path class [< a href =http://msdn.microsoft.com/en-us/library/3bdzys9w%28v=vs.100%29.aspxtarget =_ blanktitle =New Window> ^ ]为此。



使用 GetFullPath方法 [ ^ ]检索路径并 GetFileName方法 [ ^ ]用于文件名。

方法的两个链接都包含您可以使用的示例。


  string  a =  @  D:\\ \
ageswararao\dec-14-12-night\Alumini_App\Alumini_App\Resume\NN_dd.doc;
int lastIndex = a.LastIndexOf(' \\');


您好,



您的解决方案:



  string  strFilePath =  @  D:\ nageswararao \dec-14-12-night\Alumini_App\Alumini_App\Resume\NN_dd.doc ; 
MessageBox.Show(strFilePath.LastIndexOf(' \\')。ToString( ));


D:\nageswararao\dec-14-12-night\Alumini_App\Alumini_App\Resume\NN_dd.doc


In the above path I need to find the last occurrence of ''\'' and from that I would like to divide the path in two two strings.

解决方案

You can use the Path class[^] for this.

Use the GetFullPath Method[^] to retrieve the path and GetFileName Method[^] for the file name.
Both links to the methods contain examples you can use.


string a = @"D:\nageswararao\dec-14-12-night\Alumini_App\Alumini_App\Resume\NN_dd.doc";
int lastIndex = a.LastIndexOf('\\');


Hi,

Your solution:

string strFilePath = @"D:\nageswararao\dec-14-12-night\Alumini_App\Alumini_App\Resume\NN_dd.doc";
MessageBox.Show( strFilePath.LastIndexOf('\\').ToString());


这篇关于如何获取字符串中字符的最后一次出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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